summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-05-20 16:38:37 +0200
committerThomas Haller <thaller@redhat.com>2019-06-13 16:10:53 +0200
commit8b2d115f9d2a842555e91f3007f9ca0fc99623bc (patch)
treedb2db153237099718288088916baf375e505f78c
parent49c6fa2ba763955cd2a2aeab6517e7105f3e4931 (diff)
downloadNetworkManager-8b2d115f9d2a842555e91f3007f9ca0fc99623bc.tar.gz
shared: add nm_utils_g_slist_find_str() util
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c28
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h5
2 files changed, 33 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index dcca78cf93..6ed86f5916 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -2683,6 +2683,34 @@ _nm_utils_strv_cmp_n (const char *const*strv1,
/*****************************************************************************/
+/**
+ * nm_utils_g_slist_find_str:
+ * @list: the #GSList with NUL terminated strings to search
+ * @needle: the needle string to look for.
+ *
+ * Search the list for @needle and return the first found match
+ * (or %NULL if not found). Uses strcmp() for finding the first matching
+ * element.
+ *
+ * Returns: the #GSList element with @needle as string value or
+ * %NULL if not found.
+ */
+GSList *
+nm_utils_g_slist_find_str (const GSList *list,
+ const char *needle)
+{
+ nm_assert (needle);
+
+ for (; list; list = list->next) {
+ nm_assert (list->data);
+ if (nm_streq (list->data, needle))
+ return (GSList *) list;
+ }
+ return NULL;
+}
+
+/*****************************************************************************/
+
gpointer
_nm_utils_user_data_pack (int nargs, gconstpointer *args)
{
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 915e1381da..8f11a9b0c3 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -978,6 +978,11 @@ nm_utils_strv_make_deep_copied_nonnull (const char **strv)
/*****************************************************************************/
+GSList *nm_utils_g_slist_find_str (const GSList *list,
+ const char *needle);
+
+/*****************************************************************************/
+
gssize nm_utils_ptrarray_find_binary_search (gconstpointer *list,
gsize len,
gconstpointer needle,