X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fstrset%2Fstrset.h;h=9d6f1ae343f5b4904e3eaf725d26c6a89cc7f331;hb=836119375a6c477747bc85a4a384a98599610f73;hp=8d0d307e34c483d2b21351defe68d0ba0baab3c1;hpb=ab83de953730f5e5e571dbf69ffb3cc685a102dc;p=ccan diff --git a/ccan/strset/strset.h b/ccan/strset/strset.h index 8d0d307e..9d6f1ae3 100644 --- a/ccan/strset/strset.h +++ b/ccan/strset/strset.h @@ -48,60 +48,63 @@ static inline bool strset_empty(const struct strset *set) } /** - * strset_test - is this a member of this string set? + * strset_get - is this a member of this string set? * @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")) + * if (strset_get(&set, "hello")) * printf("hello is in the set\n"); */ -char *strset_test(const struct strset *set, const char *member); +char *strset_get(const struct strset *set, const char *member); /** - * strset_set - place a member in the string set. + * strset_add - place a member in the string set. * @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(). * * Example: - * if (!strset_set(&set, "goodbye")) + * if (!strset_add(&set, "goodbye")) * printf("goodbye was already in the set\n"); */ -bool strset_set(struct strset *set, const char *member); +bool strset_add(struct strset *set, const char *member); /** - * strset_clear - remove a member from the string set. + * strset_del - remove a member from the string set. * @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_add(), 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. * * Example: - * if (!strset_clear(&set, "goodbye")) + * if (!strset_del(&set, "goodbye")) * printf("goodbye was not in the set?\n"); */ -char *strset_clear(struct strset *set, const char *member); +char *strset_del(struct strset *set, const char *member); /** - * strset_destroy - remove every member from the set. + * strset_clear - remove every member from the set. * @set: the set. * * The set will be empty after this. * * Example: - * strset_destroy(&set); + * strset_clear(&set); */ -void strset_destroy(struct strset *set); +void strset_clear(struct strset *set); /** * strset_iterate - ordered iteration over a set @@ -110,16 +113,16 @@ void strset_destroy(struct strset *set); * @arg: the argument for the function (types should match). * * You should not alter the set within the @handle function! If it returns - * true, the iteration will stop. + * false, the iteration will stop. * * Example: * static bool dump_some(const char *member, int *num) * { * // Only dump out num nodes. * if (*(num--) == 0) - * return true; + * return false; * printf("%s\n", member); - * return false; + * return true; * } * * static void dump_set(const struct strset *set) @@ -136,7 +139,7 @@ void strset_destroy(struct strset *set); const char *), \ (arg)) void strset_iterate_(const struct strset *set, - bool (*handle)(const char *, void *), void *data); + bool (*handle)(const char *, void *), const void *data); /**