]> git.ozlabs.org Git - ccan/blobdiff - ccan/strmap/strmap.c
Relicense all public domain modules to CC0.
[ccan] / ccan / strmap / strmap.c
index 2b89fe0da66cdf8185b4096681175601a2a01fb0..9fa51d0d40db4cf89fb16041585d71ea163b2238 100644 (file)
@@ -39,12 +39,13 @@ void *strmap_get_(const struct strmap *map, const char *member)
 {
        struct strmap *n;
 
 {
        struct strmap *n;
 
-       /* Empty map? */
-       if (!map->u.n)
-               return NULL;
-       n = closest((struct strmap *)map, member);
-       if (streq(member, n->u.s))
-               return n->v;
+       /* Not empty map? */
+       if (map->u.n) {
+               n = closest((struct strmap *)map, member);
+               if (streq(member, n->u.s))
+                       return n->v;
+       }
+       errno = ENOENT;
        return NULL;
 }
 
        return NULL;
 }
 
@@ -129,8 +130,10 @@ char *strmap_del_(struct strmap *map, const char *member, void **valuep)
        u8 direction = 0; /* prevent bogus gcc warning. */
 
        /* Empty map? */
        u8 direction = 0; /* prevent bogus gcc warning. */
 
        /* Empty map? */
-       if (!map->u.n)
+       if (!map->u.n) {
+               errno = ENOENT;
                return NULL;
                return NULL;
+       }
 
        /* Find closest, but keep track of parent. */
        n = map;
 
        /* Find closest, but keep track of parent. */
        n = map;
@@ -148,8 +151,10 @@ char *strmap_del_(struct strmap *map, const char *member, void **valuep)
        }
 
        /* Did we find it? */
        }
 
        /* Did we find it? */
-       if (!streq(member, n->u.s))
+       if (!streq(member, n->u.s)) {
+               errno = ENOENT;
                return NULL;
                return NULL;
+       }
 
        ret = n->u.s;
        if (valuep)
 
        ret = n->u.s;
        if (valuep)
@@ -169,17 +174,19 @@ char *strmap_del_(struct strmap *map, const char *member, void **valuep)
 }
 
 static bool iterate(struct strmap n,
 }
 
 static bool iterate(struct strmap n,
-                   bool (*handle)(const char *, void *, void *), void *data)
+                   bool (*handle)(const char *, void *, void *),
+                   const void *data)
 {
        if (n.v)
 {
        if (n.v)
-               return handle(n.u.s, n.v, data);
+               return handle(n.u.s, n.v, (void *)data);
 
        return iterate(n.u.n->child[0], handle, data)
 
        return iterate(n.u.n->child[0], handle, data)
-               || iterate(n.u.n->child[1], handle, data);
+               && iterate(n.u.n->child[1], handle, data);
 }
 
 void strmap_iterate_(const struct strmap *map,
 }
 
 void strmap_iterate_(const struct strmap *map,
-                    bool (*handle)(const char *, void *, void *), void *data)
+                    bool (*handle)(const char *, void *, void *),
+                    const void *data)
 {
        /* Empty map? */
        if (!map->u.n)
 {
        /* Empty map? */
        if (!map->u.n)