src/utils_avltree.[ch]: Change avl_insert to return >0 if the key is already in the...
authorLuke Heberling <collectd@c-ware.com>
Thu, 13 Dec 2007 07:15:38 +0000 (08:15 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Thu, 13 Dec 2007 07:15:38 +0000 (08:15 +0100)
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 <octo@huhu.verplant.org>
src/utils_avltree.c
src/utils_avltree.h

index 09cf2e6..031ec47 100644 (file)
@@ -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)
                {
index 7a29a29..0fc8ea1 100644 (file)
@@ -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);