{
const char *str;
- /* Empty set? */
- if (!set->u.n)
- return NULL;
- str = closest(*set, member);
- if (streq(member, str))
- return (char *)str;
+ /* Non-empty set? */
+ if (set->u.n) {
+ str = closest(*set, member);
+ if (streq(member, str))
+ return (char *)str;
+ }
+ errno = ENOENT;
return NULL;
}
u8 direction = 0; /* prevent bogus gcc warning. */
/* Empty set? */
- if (!set->u.n)
+ if (!set->u.n) {
+ errno = ENOENT;
return NULL;
+ }
/* Find closest, but keep track of parent. */
n = set;
if (unlikely(n->u.n->byte_num == (size_t)-1)) {
const char *empty_str = n->u.n->child[0].u.s;
- if (member[0])
+ if (member[0]) {
+ errno = ENOENT;
return NULL;
+ }
/* Sew empty string back so remaining logic works */
free(n->u.n);
}
/* Did we find it? */
- if (!streq(member, n->u.s))
+ if (!streq(member, n->u.s)) {
+ errno = ENOENT;
return NULL;
+ }
ret = n->u.s;
* @set: the set.
* @member: the string to search for.
*
- * Returns the member, or NULL if it isn't in the set.
+ * Returns the member, or NULL if it isn't in the set (and sets errno
+ * = ENOENT).
*
* Example:
* if (strset_test(&set, "hello"))
* @set: the set.
* @member: the string to remove from the set.
*
- * This returns the string which was passed to strset_set(), or NULL.
+ * This returns the string which was passed to strset_set(), or NULL if
+ * the string was not in the map (in which case it sets errno = ENOENT).
+ *
* This means that if you allocated a string (eg. using strdup()), you can
* free it here.
*
char *dup = strdup(str);
/* This is how many tests you plan to run */
- plan_tests(26);
+ plan_tests(36);
strset_init(&set);
ok1(!strset_test(&set, str));
+ ok1(errno == ENOENT);
ok1(!strset_test(&set, none));
+ ok1(errno == ENOENT);
ok1(!strset_clear(&set, str));
+ ok1(errno == ENOENT);
ok1(!strset_clear(&set, none));
+ ok1(errno == ENOENT);
ok1(strset_set(&set, str));
ok1(strset_test(&set, str));
/* We compare the string, not the pointer. */
ok1(strset_test(&set, dup));
ok1(!strset_test(&set, none));
+ ok1(errno == ENOENT);
/* Add of duplicate should fail. */
ok1(!strset_set(&set, dup));
/* Delete should return original string. */
ok1(strset_clear(&set, dup) == str);
ok1(!strset_test(&set, str));
+ ok1(errno == ENOENT);
ok1(!strset_test(&set, none));
+ ok1(errno == ENOENT);
/* Try insert and delete of empty string. */
ok1(strset_set(&set, none));
ok1(strset_test(&set, none));
ok1(!strset_test(&set, str));
+ ok1(errno == ENOENT);
/* Delete should return original string. */
ok1(strset_clear(&set, "") == none);
ok1(!strset_test(&set, str));
+ ok1(errno == ENOENT);
ok1(!strset_test(&set, none));
+ ok1(errno == ENOENT);
/* Both at once... */
ok1(strset_set(&set, none));