basic/set: add set_ensure_put()

It's such a common operation to allocate the set and put an item in it,
that it deserves a helper. set_ensure_put() has the same return values
as set_put().

Comes with tests!
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-06-22 16:32:37 +02:00
parent aaffd34933
commit 0f9ccd9552
3 changed files with 36 additions and 0 deletions
+3
View File
@@ -120,6 +120,9 @@ static inline char **set_get_strv(Set *s) {
return _hashmap_get_strv(HASHMAP_BASE(s));
}
int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS);
#define set_ensure_put(s, hash_ops, key) _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
int set_consume(Set *s, void *value);
int set_put_strdup(Set **s, const char *p);
int set_put_strdupv(Set **s, char **l);