diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2022-05-04 11:07:21 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2022-06-15 12:13:26 +0200 |
commit | e2fc81e2119ec658d76059009555cca8f6e0c231 (patch) | |
tree | 942a6c8af06d773127ed7bc38c7ddb7c1bfe76db | |
parent | 7d499c4da6c7995134a28e31972ca96754eced4e (diff) | |
download | NetworkManager-e2fc81e2119ec658d76059009555cca8f6e0c231.tar.gz |
glib-aux: add g_ptr_array_find() compat routine
I want it but GLib is no good. Sad.
-rw-r--r-- | src/libnm-glib-aux/nm-glib.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-glib.h b/src/libnm-glib-aux/nm-glib.h index f3be3b32a4..2dc86d7b4e 100644 --- a/src/libnm-glib-aux/nm-glib.h +++ b/src/libnm-glib-aux/nm-glib.h @@ -307,6 +307,33 @@ _nm_g_ptr_array_insert(GPtrArray *array, int index_, gpointer data) /*****************************************************************************/ +#if !GLIB_CHECK_VERSION(2, 54, 0) +static inline gboolean +g_ptr_array_find(GPtrArray *haystack, gconstpointer needle, guint *index_) +{ + guint i; + g_return_val_if_fail(haystack, FALSE); + + for (i = 0; i < haystack->len; i++) { + if (haystack->pdata[i] == needle) { + if (index_) + *index_ = i; + return TRUE; + } + } + return FALSE; +} +#else +#define g_ptr_array_find(haystack, needle, index_) \ + ({ \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + g_ptr_array_find(haystack, needle, index_); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ + }) +#endif + +/*****************************************************************************/ + #if !GLIB_CHECK_VERSION(2, 40, 0) static inline gboolean _g_key_file_save_to_file(GKeyFile *key_file, const char *filename, GError **error) |