chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e31165b
)
strv: make strv_extend() smarter
author
Lennart Poettering
<lennart@poettering.net>
Thu, 17 Jan 2013 23:47:19 +0000
(
00:47
+0100)
committer
Lennart Poettering
<lennart@poettering.net>
Thu, 17 Jan 2013 23:47:19 +0000
(
00:47
+0100)
src/shared/strv.c
patch
|
blob
|
history
diff --git
a/src/shared/strv.c
b/src/shared/strv.c
index aed45d26128be847302ab570416387eb0d0a99a1..2d556f4a076a664a71ffc70f0bd77d675e531bde 100644
(file)
--- 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;
}