summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-06-13 18:13:23 +0200
committerThomas Haller <thaller@redhat.com>2019-06-16 09:36:34 +0200
commit07d977db5b3f5df7e544ed8dadf075ab5f15cc26 (patch)
tree1c83261c46cb84e1c29378f4422075e00e040a0a
parent1fc36dc58fd1a9779b973f477e2b6820a253fc7e (diff)
downloadNetworkManager-07d977db5b3f5df7e544ed8dadf075ab5f15cc26.tar.gz
shared: add nm_utils_g_slist_strlist_cmp() util
Usually we avoid GSList, because I think it's not a great data type. Anyway, our match-specs are just a GSList of strings, so we need some API to handle them.
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c19
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index 6ed86f5916..c8b0eef84e 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -2709,6 +2709,25 @@ nm_utils_g_slist_find_str (const GSList *list,
return NULL;
}
+/**
+ * nm_utils_g_slist_strlist_cmp:
+ * @a: the left #GSList of strings
+ * @b: the right #GSList of strings to compare.
+ *
+ * Compares two string lists. The data elements are compared with
+ * strcmp(), alloing %NULL elements.
+ *
+ * Returns: 0, 1, or -1, depending on how the lists compare.
+ */
+int
+nm_utils_g_slist_strlist_cmp (const GSList *a, const GSList *b)
+{
+ for (; a && b; a = a->next, b = b->next)
+ NM_CMP_DIRECT_STRCMP0 (a->data, b->data);
+ NM_CMP_SELF (a, b);
+ return 0;
+}
+
/*****************************************************************************/
gpointer
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 8f11a9b0c3..a8f2966b38 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -981,6 +981,8 @@ nm_utils_strv_make_deep_copied_nonnull (const char **strv)
GSList *nm_utils_g_slist_find_str (const GSList *list,
const char *needle);
+int nm_utils_g_slist_strlist_cmp (const GSList *a, const GSList *b);
+
/*****************************************************************************/
gssize nm_utils_ptrarray_find_binary_search (gconstpointer *list,