For two string lists merge one into the other one.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virstring.c | 36 ++++++++++++++++++++++++++++++++++++
src/util/virstring.h | 3 +++
3 files changed, 40 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d5c3b9abb..d807cdca6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2764,6 +2764,7 @@ virStringListGetFirstWithPrefix;
virStringListHasString;
virStringListJoin;
virStringListLength;
+virStringListMerge;
virStringListRemove;
virStringMatch;
virStringParsePort;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index b2ebce27f..47d9efba2 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -239,6 +239,42 @@ virStringListRemove(char ***strings,
}
+/**
+ * virStringListMerge:
+ * @dst: a NULL-terminated array of strings to expand
+ * @src: a NULL-terminated array of strings
+ *
+ * Merges @src into @dst. Upon successful return from this
+ * function, @dst is resized to $(dst + src) elements and @src is
+ * freed.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+int
+virStringListMerge(char ***dst,
+ char ***src)
+{
+ size_t dst_len, src_len, i;
+
+ if (!src || !*src)
+ return 0;
+
+ dst_len = virStringListLength((const char **) *dst);
+ src_len = virStringListLength((const char **) *src);
+
+ if (VIR_REALLOC_N(*dst, dst_len + src_len + 1) < 0)
+ return -1;
+
+ for (i = 0; i <= src_len; i++)
+ (*dst)[i + dst_len] = (*src)[i];
+
+ /* Don't call virStringListFree() as it would free strings in
+ * @src. */
+ VIR_FREE(*src);
+ return 0;
+}
+
+
/**
* virStringListCopy:
* @dst: where to store the copy of @strings
diff --git a/src/util/virstring.h b/src/util/virstring.h
index b19abaf9f..f42aaff62 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -46,6 +46,9 @@ char **virStringListAdd(const char **strings,
void virStringListRemove(char ***strings,
const char *item);
+int virStringListMerge(char ***dst,
+ char ***src);
+
int virStringListCopy(char ***dst,
const char **src);
--
2.13.6