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:
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user