summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-24 21:54:22 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-25 21:58:38 +0100
commit0264d0726fac78f7d689ded632987ff9edfc03d2 (patch)
treeafd234971ceb167d72ae352f76dbb087c68c8e26 /src
parenteed857b71702f8551b46b66b31fa0d08583cf23c (diff)
util-lib: add ordered_set_ensure_allocated()
ordered_set_ensure_allocated() does for an OrderedSet, what set_ensure_allicated() does for a Set.
Diffstat (limited to 'src')
-rw-r--r--src/basic/ordered-set.h11
-rw-r--r--src/basic/set.h1
2 files changed, 11 insertions, 1 deletions
diff --git a/src/basic/ordered-set.h b/src/basic/ordered-set.h
index 6c617ab305..da10e90ff2 100644
--- a/src/basic/ordered-set.h
+++ b/src/basic/ordered-set.h
@@ -29,6 +29,17 @@ static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) {
return (OrderedSet*) ordered_hashmap_new(ops);
}
+static inline int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops) {
+ if (*s)
+ return 0;
+
+ *s = ordered_set_new(ops);
+ if (!*s)
+ return -ENOMEM;
+
+ return 0;
+}
+
static inline OrderedSet* ordered_set_free(OrderedSet *s) {
ordered_hashmap_free((OrderedHashmap*) s);
return NULL;
diff --git a/src/basic/set.h b/src/basic/set.h
index 4554ef2d49..5fd7de08f9 100644
--- a/src/basic/set.h
+++ b/src/basic/set.h
@@ -27,7 +27,6 @@
Set *internal_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
#define set_new(ops) internal_set_new(ops HASHMAP_DEBUG_SRC_ARGS)
-
static inline Set *set_free(Set *s) {
internal_hashmap_free(HASHMAP_BASE(s));
return NULL;