};
/* Closest member to this in a non-empty map. */
-static struct strmap *closest(struct strmap *n, const char *member)
+static struct strmap *closest(struct strmap *n, const char *member, size_t len)
{
- size_t len = strlen(member);
const u8 *bytes = (const u8 *)member;
/* Anything with NULL value is a node. */
return n;
}
-void *strmap_get_(const struct strmap *map, const char *member)
+void *strmap_getn_(const struct strmap *map,
+ const char *member, size_t memberlen)
{
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, memberlen);
+ if (!strncmp(member, n->u.s, memberlen) && !n->u.s[memberlen])
+ return n->v;
+ }
+ errno = ENOENT;
return NULL;
}
+void *strmap_get_(const struct strmap *map, const char *member)
+{
+ return strmap_getn_(map, member, strlen(member));
+}
+
bool strmap_add_(struct strmap *map, const char *member, const void *value)
{
size_t len = strlen(member);
}
/* Find closest existing member. */
- n = closest(map, member);
+ n = closest(map, member, len);
/* Find where they differ. */
for (byte_num = 0; n->u.s[byte_num] == member[byte_num]; byte_num++) {
u8 direction = 0; /* prevent bogus gcc warning. */
/* Empty map? */
- if (!map->u.n)
+ if (!map->u.n) {
+ errno = ENOENT;
return NULL;
+ }
/* Find closest, but keep track of parent. */
n = map;
}
/* Did we find it? */
- if (!streq(member, n->u.s))
+ if (!streq(member, n->u.s)) {
+ errno = ENOENT;
return NULL;
+ }
ret = n->u.s;
if (valuep)
}
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)
- 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)
- || iterate(n.u.n->child[1], handle, data);
+ && iterate(n.u.n->child[1], handle, data);
}
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)