]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/hashmap.c
basic/set: let set_put_strdup() create the set with string hash ops
[thirdparty/systemd.git] / src / basic / hashmap.c
index 4853514c96a6e66a608d03b3ad76271c456d1ac9..7abe62fa93768793bf79cae6e244850cb8997032 100644 (file)
@@ -1793,23 +1793,28 @@ int hashmap_put_strdup(Hashmap **h, const char *k, const char *v) {
         return 0;
 }
 
-int set_put_strdup(Set *s, const char *p) {
+int set_put_strdup(Set **s, const char *p) {
         char *c;
+        int r;
 
         assert(s);
         assert(p);
 
-        if (set_contains(s, (char*) p))
+        r = set_ensure_allocated(s, &string_hash_ops_free);
+        if (r < 0)
+                return r;
+
+        if (set_contains(*s, (char*) p))
                 return 0;
 
         c = strdup(p);
         if (!c)
                 return -ENOMEM;
 
-        return set_consume(s, c);
+        return set_consume(*s, c);
 }
 
-int set_put_strdupv(Set *s, char **l) {
+int set_put_strdupv(Set **s, char **l) {
         int n = 0, r;
         char **i;