X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fstrset%2Fstrset.c;fp=ccan%2Fstrset%2Fstrset.c;h=7c64b0cd016631017024da239cc29ad7e5470ec0;hb=2578442d9f40350f51cca44eeef60768dbae2dc6;hp=8088db47e808e3adb40f5bf583a6a8e6babeec59;hpb=ed1b25bbd01f79b5b333fd28b53455d2c91b831f;p=ccan diff --git a/ccan/strset/strset.c b/ccan/strset/strset.c index 8088db47..7c64b0cd 100644 --- a/ccan/strset/strset.c +++ b/ccan/strset/strset.c @@ -19,6 +19,7 @@ #include #include #include +#include struct node { /* To differentiate us from strings. */ @@ -75,8 +76,10 @@ static bool set_string(struct strset *set, /* Substitute magic empty node if this is the empty string */ if (unlikely(!member[0])) { n->u.n = malloc(sizeof(*n->u.n)); - if (unlikely(!n->u.n)) + if (unlikely(!n->u.n)) { + errno = ENOMEM; return false; + } n->u.n->nul_byte = '\0'; n->u.n->byte_num = (size_t)-1; /* Attach the string to child[0] */ @@ -108,6 +111,7 @@ bool strset_set(struct strset *set, const char *member) for (byte_num = 0; str[byte_num] == member[byte_num]; byte_num++) { if (member[byte_num] == '\0') { /* All identical! */ + errno = EEXIST; return false; } } @@ -122,7 +126,7 @@ bool strset_set(struct strset *set, const char *member) /* Allocate new node. */ newn = malloc(sizeof(*newn)); if (!newn) { - /* FIXME */ + errno = ENOMEM; return false; } newn->nul_byte = '\0';