summaryrefslogtreecommitdiff
path: root/strv.c
diff options
context:
space:
mode:
Diffstat (limited to 'strv.c')
-rw-r--r--strv.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/strv.c b/strv.c
index ecad6d5980..faa878c006 100644
--- a/strv.c
+++ b/strv.c
@@ -115,3 +115,33 @@ fail:
free(a);
return NULL;
}
+
+char **strv_merge(char **a, char **b) {
+ char **r, **k;
+
+ if (!a)
+ return strv_copy(b);
+
+ if (!b)
+ return strv_copy(a);
+
+ if (!(r = new(char*, strv_length(a)+strv_length(b)+1)))
+ return NULL;
+
+ for (k = r; *a; k++, a++)
+ if (!(*k = strdup(*a)))
+ goto fail;
+ for (; *b; k++, b++)
+ if (!(*k = strdup(*b)))
+ goto fail;
+
+ *k = NULL;
+ return r;
+
+fail:
+ for (k--; k >= r; k--)
+ free(*k);
+
+ return NULL;
+
+}