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:
parent
e31165b262
commit
82dde599ed
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user