#include <ccan/ilog/ilog.h>
 #include <assert.h>
 #include <stdlib.h>
+#include <errno.h>
 
 struct node {
        /* To differentiate us from strings. */
        /* 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] */
        for (byte_num = 0; str[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->nul_byte = '\0';
 
  * @set: the set.
  * @member: the string to place in the set.
  *
- * This returns false if we run out of memory, or (more normally) if that
- * string already appears in the set.
+ * This returns false if we run out of memory (errno = ENOMEM), or
+ * (more normally) if that string already appears in the set (EEXIST).
  *
  * Note that the pointer is placed in the set, the string is not copied.  If
  * you want a copy in the set, use strdup().
 
        char *dup = strdup(str);
 
        /* This is how many tests you plan to run */
-       plan_tests(24);
+       plan_tests(26);
 
        strset_init(&set);
 
        ok1(strset_test(&set, dup));
        ok1(!strset_test(&set, none));
 
+       /* Add of duplicate should fail. */
+       ok1(!strset_set(&set, dup));
+       ok1(errno == EEXIST);
+
        /* Delete should return original string. */
        ok1(strset_clear(&set, dup) == str);
        ok1(!strset_test(&set, str));