]> git.ozlabs.org Git - ccan/blobdiff - ccan/strmap/strmap.c
strmap: set errno on strmap_add() failures.
[ccan] / ccan / strmap / strmap.c
index 7d03cca43ad7ff709bdcd9699ac31b5ad74fe309..2b89fe0da66cdf8185b4096681175601a2a01fb0 100644 (file)
@@ -5,6 +5,7 @@
 #include <ccan/ilog/ilog.h>
 #include <assert.h>
 #include <stdlib.h>
+#include <errno.h>
 
 struct node {
        /* These point to strings or nodes. */
@@ -72,6 +73,7 @@ bool strmap_add_(struct strmap *map, const char *member, const void *value)
        for (byte_num = 0; n->u.s[byte_num] == member[byte_num]; byte_num++) {
                if (member[byte_num] == '\0') {
                        /* All identical! */
+                       errno = EEXIST;
                        return false;
                }
        }
@@ -86,7 +88,7 @@ bool strmap_add_(struct strmap *map, const char *member, const void *value)
        /* Allocate new node. */
        newn = malloc(sizeof(*newn));
        if (!newn) {
-               /* FIXME */
+               errno = ENOMEM;
                return false;
        }
        newn->byte_num = byte_num;