summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-06-02 14:19:20 +0200
committerThomas Haller <thaller@redhat.com>2021-06-04 09:29:21 +0200
commit851267b6e768b53728018a07019cd28546a51082 (patch)
tree0787c183bcaced4c5294dc75955f0dd2f4aa2b06
parentb0acbe504f319456fc36fea2530c75b109f079ea (diff)
downloadNetworkManager-851267b6e768b53728018a07019cd28546a51082.tar.gz
glib-aux: add nm_strvarray_find_first() helper
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index ac45bf4a67..d34307d7bf 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -2795,8 +2795,8 @@ nm_strvarray_set_strv(GArray **array, const char *const *strv)
nm_strvarray_add(*array, strv[0]);
}
-static inline gboolean
-nm_strvarray_remove_first(GArray *strv, const char *needle)
+static inline gssize
+nm_strvarray_find_first(GArray *strv, const char *needle)
{
guint i;
@@ -2804,13 +2804,25 @@ nm_strvarray_remove_first(GArray *strv, const char *needle)
if (strv) {
for (i = 0; i < strv->len; i++) {
- if (nm_streq(needle, g_array_index(strv, const char *, i))) {
- g_array_remove_index(strv, i);
- return TRUE;
- }
+ if (nm_streq(needle, g_array_index(strv, const char *, i)))
+ return i;
}
}
- return FALSE;
+ return -1;
+}
+
+static inline gboolean
+nm_strvarray_remove_first(GArray *strv, const char *needle)
+{
+ gssize idx;
+
+ nm_assert(needle);
+
+ idx = nm_strvarray_find_first(strv, needle);
+ if (idx < 0)
+ return FALSE;
+ g_array_remove_index(strv, idx);
+ return TRUE;
}
/*****************************************************************************/