summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-01-18 00:47:19 +0100
committerLennart Poettering <lennart@poettering.net>2013-01-18 00:47:19 +0100
commit82dde599ed2b8aa4877900d84e7a2ddc31ef8da2 (patch)
tree19ac0fb3a06d39417743c46828526dbf4c616e5c /src/shared
parente31165b26212b45e135fd4cd7d618a081d50bd28 (diff)
strv: make strv_extend() smarter
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/strv.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/shared/strv.c b/src/shared/strv.c
index aed45d2612..2d556f4a07 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -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;
}