|
|
147b37 |
From a2798982df8432b5d26f247516ca5a43e0a94c58 Mon Sep 17 00:00:00 2001
|
|
|
147b37 |
Message-Id: <a2798982df8432b5d26f247516ca5a43e0a94c58@dist-git>
|
|
|
147b37 |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
147b37 |
Date: Mon, 9 Apr 2018 15:46:48 +0200
|
|
|
147b37 |
Subject: [PATCH] util: Introduce virStringListMerge
|
|
|
147b37 |
MIME-Version: 1.0
|
|
|
147b37 |
Content-Type: text/plain; charset=UTF-8
|
|
|
147b37 |
Content-Transfer-Encoding: 8bit
|
|
|
147b37 |
|
|
|
147b37 |
https://bugzilla.redhat.com/show_bug.cgi?id=1564996
|
|
|
147b37 |
|
|
|
147b37 |
For two string lists merge one into the other one.
|
|
|
147b37 |
|
|
|
147b37 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
147b37 |
(cherry picked from commit 72bf14d3456373130cd47157c0062e9125318716)
|
|
|
147b37 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
147b37 |
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
|
|
|
147b37 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
147b37 |
---
|
|
|
147b37 |
src/libvirt_private.syms | 1 +
|
|
|
147b37 |
src/util/virstring.c | 36 ++++++++++++++++++++++++++++++++++++
|
|
|
147b37 |
src/util/virstring.h | 3 +++
|
|
|
147b37 |
3 files changed, 40 insertions(+)
|
|
|
147b37 |
|
|
|
147b37 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
147b37 |
index 9c64d0cb97..15cc83931a 100644
|
|
|
147b37 |
--- a/src/libvirt_private.syms
|
|
|
147b37 |
+++ b/src/libvirt_private.syms
|
|
|
147b37 |
@@ -2775,6 +2775,7 @@ virStringListGetFirstWithPrefix;
|
|
|
147b37 |
virStringListHasString;
|
|
|
147b37 |
virStringListJoin;
|
|
|
147b37 |
virStringListLength;
|
|
|
147b37 |
+virStringListMerge;
|
|
|
147b37 |
virStringListRemove;
|
|
|
147b37 |
virStringMatch;
|
|
|
147b37 |
virStringParsePort;
|
|
|
147b37 |
diff --git a/src/util/virstring.c b/src/util/virstring.c
|
|
|
147b37 |
index b2ebce27ff..47d9efba25 100644
|
|
|
147b37 |
--- a/src/util/virstring.c
|
|
|
147b37 |
+++ b/src/util/virstring.c
|
|
|
147b37 |
@@ -239,6 +239,42 @@ virStringListRemove(char ***strings,
|
|
|
147b37 |
}
|
|
|
147b37 |
|
|
|
147b37 |
|
|
|
147b37 |
+/**
|
|
|
147b37 |
+ * virStringListMerge:
|
|
|
147b37 |
+ * @dst: a NULL-terminated array of strings to expand
|
|
|
147b37 |
+ * @src: a NULL-terminated array of strings
|
|
|
147b37 |
+ *
|
|
|
147b37 |
+ * Merges @src into @dst. Upon successful return from this
|
|
|
147b37 |
+ * function, @dst is resized to $(dst + src) elements and @src is
|
|
|
147b37 |
+ * freed.
|
|
|
147b37 |
+ *
|
|
|
147b37 |
+ * Returns 0 on success, -1 otherwise.
|
|
|
147b37 |
+ */
|
|
|
147b37 |
+int
|
|
|
147b37 |
+virStringListMerge(char ***dst,
|
|
|
147b37 |
+ char ***src)
|
|
|
147b37 |
+{
|
|
|
147b37 |
+ size_t dst_len, src_len, i;
|
|
|
147b37 |
+
|
|
|
147b37 |
+ if (!src || !*src)
|
|
|
147b37 |
+ return 0;
|
|
|
147b37 |
+
|
|
|
147b37 |
+ dst_len = virStringListLength((const char **) *dst);
|
|
|
147b37 |
+ src_len = virStringListLength((const char **) *src);
|
|
|
147b37 |
+
|
|
|
147b37 |
+ if (VIR_REALLOC_N(*dst, dst_len + src_len + 1) < 0)
|
|
|
147b37 |
+ return -1;
|
|
|
147b37 |
+
|
|
|
147b37 |
+ for (i = 0; i <= src_len; i++)
|
|
|
147b37 |
+ (*dst)[i + dst_len] = (*src)[i];
|
|
|
147b37 |
+
|
|
|
147b37 |
+ /* Don't call virStringListFree() as it would free strings in
|
|
|
147b37 |
+ * @src. */
|
|
|
147b37 |
+ VIR_FREE(*src);
|
|
|
147b37 |
+ return 0;
|
|
|
147b37 |
+}
|
|
|
147b37 |
+
|
|
|
147b37 |
+
|
|
|
147b37 |
/**
|
|
|
147b37 |
* virStringListCopy:
|
|
|
147b37 |
* @dst: where to store the copy of @strings
|
|
|
147b37 |
diff --git a/src/util/virstring.h b/src/util/virstring.h
|
|
|
147b37 |
index cfd91be314..1fd43f98b7 100644
|
|
|
147b37 |
--- a/src/util/virstring.h
|
|
|
147b37 |
+++ b/src/util/virstring.h
|
|
|
147b37 |
@@ -46,6 +46,9 @@ char **virStringListAdd(const char **strings,
|
|
|
147b37 |
void virStringListRemove(char ***strings,
|
|
|
147b37 |
const char *item);
|
|
|
147b37 |
|
|
|
147b37 |
+int virStringListMerge(char ***dst,
|
|
|
147b37 |
+ char ***src);
|
|
|
147b37 |
+
|
|
|
147b37 |
int virStringListCopy(char ***dst,
|
|
|
147b37 |
const char **src);
|
|
|
147b37 |
|
|
|
147b37 |
--
|
|
|
147b37 |
2.17.0
|
|
|
147b37 |
|