#include <ccan/ilog/ilog.h>
#include <assert.h>
#include <stdlib.h>
+#include <errno.h>
struct node {
/* These point to strings or nodes. */
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;
* @member: the string to place in the map.
* @v: the (non-NULL) value.
*
- * This returns false if we run out of memory, or (more normally) if that
- * string already appears in the map.
+ * This returns false if we run out of memory (errno = ENOMEM), or
+ * (more normally) if that string already appears in the map (EEXIST).
*
* Note that the pointer is placed in the map, the string is not copied. If
* you want a copy in the map, use strdup(). Similarly for the value.
char *v;
/* This is how many tests you plan to run */
- plan_tests(31);
+ plan_tests(32);
strmap_init(&map);
/* Add a duplicate should fail. */
ok1(!strmap_add(&map, dup, val));
+ ok1(errno == EEXIST);
ok1(strmap_get(&map, dup) == val);
/* Delete should return original string. */