#include <ccan/ilog/ilog.h>
#include <assert.h>
#include <stdlib.h>
+#include <errno.h>
struct node {
/* These point to strings or nodes. */
{
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;
}
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;
}
}
/* Allocate new node. */
newn = malloc(sizeof(*newn));
if (!newn) {
- /* FIXME */
+ errno = ENOMEM;
return false;
}
newn->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)