summaryrefslogtreecommitdiffstats
path: root/src/basic/hashmap.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-06-03 14:25:18 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-06-22 16:32:37 +0200
commit0f9ccd95525c9869b6a23b71f6b7dbb2a7038674 (patch)
treeaa9db2667955d7faaae6a65eb008ff2d2ab95045 /src/basic/hashmap.c
parentsd-device: use set_put_strdup() in one more place (diff)
downloadsystemd-0f9ccd95525c9869b6a23b71f6b7dbb2a7038674.tar.xz
systemd-0f9ccd95525c9869b6a23b71f6b7dbb2a7038674.zip
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!
Diffstat (limited to 'src/basic/hashmap.c')
-rw-r--r--src/basic/hashmap.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 15c8c4723c..c876662a0b 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -1247,6 +1247,16 @@ int set_put(Set *s, const void *key) {
return hashmap_put_boldly(s, hash, &swap, true);
}
+int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS) {
+ int r;
+
+ r = _set_ensure_allocated(s, hash_ops HASHMAP_DEBUG_PASS_ARGS);
+ if (r < 0)
+ return r;
+
+ return set_put(*s, key);
+}
+
int hashmap_replace(Hashmap *h, const void *key, void *value) {
struct swap_entries swap;
struct plain_hashmap_entry *e;