From 8798c7ec333eb16410161d99487ab0bee4d9adc3 Mon Sep 17 00:00:00 2001 From: Luke Heberling Date: Thu, 13 Dec 2007 08:15:38 +0100 Subject: [PATCH] src/utils_avltree.[ch]: Change avl_insert to return >0 if the key is already in the tree. I'd like to be able to tell when avl_insert fails because of a duplicate key as opposed to when it fails due to out of memory or other condition. Signed-off-by: Florian Forster --- src/utils_avltree.c | 2 +- src/utils_avltree.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils_avltree.c b/src/utils_avltree.c index 09cf2e6f..031ec477 100644 --- a/src/utils_avltree.c +++ b/src/utils_avltree.c @@ -518,7 +518,7 @@ int avl_insert (avl_tree_t *t, void *key, void *value) if (cmp == 0) { free_node (new); - return (-1); + return (1); } else if (cmp < 0) { diff --git a/src/utils_avltree.h b/src/utils_avltree.h index 7a29a294..0fc8ea15 100644 --- a/src/utils_avltree.h +++ b/src/utils_avltree.h @@ -77,8 +77,8 @@ void avl_destroy (avl_tree_t *t); * `value' Value to be stored. * * RETURN VALUE - * Zero upon success and non-zero upon failure and if the key is already - * stored in the tree. + * Zero upon success, non-zero otherwise. It's less than zero if an error + * occurred or greater than zero if the key is already stored in the tree. */ int avl_insert (avl_tree_t *t, void *key, void *value); -- 2.30.2