diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-11-24 21:54:22 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-11-25 21:58:38 +0100 |
commit | 0264d0726fac78f7d689ded632987ff9edfc03d2 (patch) | |
tree | afd234971ceb167d72ae352f76dbb087c68c8e26 /src/basic/ordered-set.h | |
parent | resolved: enforce a maximum limit on both dns servers and search domains (diff) | |
download | systemd-0264d0726fac78f7d689ded632987ff9edfc03d2.tar.xz systemd-0264d0726fac78f7d689ded632987ff9edfc03d2.zip |
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/basic/ordered-set.h')
-rw-r--r-- | src/basic/ordered-set.h | 11 |
1 files changed, 11 insertions, 0 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; |