Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 2:
- new patch
src/libvirt_private.syms | 1 +
src/util/virstring.c | 29 +++++++++++++++++++++++++++++
src/util/virstring.h | 2 ++
3 files changed, 32 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c1542847f4..89cd20eece 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3438,6 +3438,7 @@ virStringHasControlChars;
virStringHasSuffix;
virStringIsEmpty;
virStringIsPrintable;
+virStringListRemoveDuplicates;
virStringMatch;
virStringMatchesNameSuffix;
virStringParsePort;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 81c9aff304..bc9b6cd40e 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -1065,3 +1065,32 @@ virStringParseVersion(unsigned long long *version,
return 0;
}
+
+
+/**
+ * virStringListRemoveDuplicates:
+ * @list: pointer to a sorted NULL-terminated string list
+ *
+ * Replace the list pointed to by @list with a new list without duplicate
+ * strings. The original list has to be sorted.
+ */
+void
+virStringListRemoveDuplicates(char ***list)
+{
+ size_t len = g_strv_length(*list);
+ char **unique;
+ size_t n = 0;
+ size_t i;
+
+ unique = g_malloc0_n(len + 1, sizeof(char *));
+
+ for (i = 0; i < len; i++) {
+ if (n > 0 && STREQ_NULLABLE(unique[n - 1], (*list)[i]))
+ g_free((*list)[i]);
+ else
+ unique[n++] = (*list)[i];
+ }
+
+ g_free(*list);
+ *list = g_renew(char *, unique, n + 1);
+}
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 8f9b1edc8f..31a404e106 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -138,3 +138,5 @@ int virStringParseYesNo(const char *str,
int virStringParseVersion(unsigned long long *version,
const char *str,
bool allowMissing);
+
+void virStringListRemoveDuplicates(char ***list);
--
2.47.0