]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: add ordered_set_ensure_allocated()
authorLennart Poettering <lennart@poettering.net>
Tue, 24 Nov 2015 20:54:22 +0000 (21:54 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 25 Nov 2015 20:58:38 +0000 (21:58 +0100)
ordered_set_ensure_allocated() does for an OrderedSet, what
set_ensure_allicated() does for a Set.

src/basic/ordered-set.h
src/basic/set.h

index 6c617ab3055eb02607a852c5f51e0a9b112ace64..da10e90ff2811cdb4979b81536c165c63a3bce9d 100644 (file)
@@ -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;
index 4554ef2d49fae8b19191484437f578daa06c2824..5fd7de08f9ec371b418bb02b6ca20646f351e9fe 100644 (file)
@@ -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;