1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +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) {
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;
}