From: Luke Heberling Date: Thu, 13 Dec 2007 07:15:38 +0000 (+0100) Subject: src/utils_avltree.[ch]: Change avl_insert to return >0 if the key is already in the... X-Git-Tag: collectd-4.3.0beta0~62^2~1 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=8798c7ec333eb16410161d99487ab0bee4d9adc3 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 --- 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);