summaryrefslogtreecommitdiff
path: root/src/shared/strv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/strv.c')
-rw-r--r--src/shared/strv.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 7bcfabbf1a..e57e0ee7bf 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -387,32 +387,43 @@ fail:
return NULL;
}
-int strv_extend(char ***l, const char *value) {
+int strv_push(char ***l, char *value) {
char **c;
- char *v;
unsigned n;
if (!value)
return 0;
- v = strdup(value);
- if (!v)
- return -ENOMEM;
-
n = strv_length(*l);
c = realloc(*l, sizeof(char*) * (n + 2));
- if (!c) {
- free(v);
+ if (!c)
return -ENOMEM;
- }
- c[n] = v;
+ c[n] = value;
c[n+1] = NULL;
*l = c;
return 0;
}
+int strv_extend(char ***l, const char *value) {
+ char *v;
+ int r;
+
+ if (!value)
+ return 0;
+
+ v = strdup(value);
+ if (!v)
+ return -ENOMEM;
+
+ r = strv_push(l, v);
+ if (r < 0)
+ free(v);
+
+ return r;
+}
+
char **strv_uniq(char **l) {
char **i;