chiark / gitweb /
strv: make strv_extend() smarter
authorLennart Poettering <lennart@poettering.net>
Thu, 17 Jan 2013 23:47:19 +0000 (00:47 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 17 Jan 2013 23:47:19 +0000 (00:47 +0100)
src/shared/strv.c

index aed45d2..2d556f4 100644 (file)
@@ -372,15 +372,26 @@ fail:
 
 int strv_extend(char ***l, const char *value) {
         char **c;
+        char *v;
+        unsigned n;
 
         if (!value)
                 return 0;
 
-        c = strv_append(*l, value);
-        if (!c)
+        v = strdup(value);
+        if (!v)
                 return -ENOMEM;
 
-        strv_free(*l);
+        n = strv_length(*l);
+        c = realloc(*l, sizeof(char*) * (n + 2));
+        if (!c) {
+                free(v);
+                return -ENOMEM;
+        }
+
+        c[n] = v;
+        c[n+1] = NULL;
+
         *l = c;
         return 0;
 }