1
0
mirror of https://github.com/systemd/systemd.git synced 2025-08-25 13:49:55 +03:00

strv: make strv_extend() smarter

This commit is contained in:
Lennart Poettering
2013-01-18 00:47:19 +01:00
parent e31165b262
commit 82dde599ed

View File

@ -372,15 +372,26 @@ fail:
int strv_extend(char ***l, const char *value) { int strv_extend(char ***l, const char *value) {
char **c; char **c;
char *v;
unsigned n;
if (!value) if (!value)
return 0; return 0;
c = strv_append(*l, value); v = strdup(value);
if (!c) if (!v)
return -ENOMEM; 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; *l = c;
return 0; return 0;
} }