diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2021-03-01 15:07:05 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2021-03-01 15:07:51 +0100 |
commit | 76b2e7336ebff26d3cf28dc584859aa5ee6ba6bb (patch) | |
tree | 176020d3dde7c80a386a17b0d92dd5e24f6b35f3 | |
parent | 7b8427c8fdd4cd879c97aa680fd95908fab3e2c7 (diff) |
libqmi-glib,helpers: import ptr array lookup with GEqualFunc from GLib 2.54
This fixes the build when using GLib < 2.54.
-rw-r--r-- | src/libqmi-glib/qmi-helpers.c | 28 | ||||
-rw-r--r-- | src/libqmi-glib/qmi-helpers.h | 14 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/libqmi-glib/qmi-helpers.c b/src/libqmi-glib/qmi-helpers.c index 56296e0..27578f5 100644 --- a/src/libqmi-glib/qmi-helpers.c +++ b/src/libqmi-glib/qmi-helpers.c @@ -691,3 +691,31 @@ qmi_helpers_list_links (GFile *sysfs_file, *out_links = g_steal_pointer (&links); return TRUE; } + +#if !GLIB_CHECK_VERSION(2,54,0) + +gboolean +qmi_ptr_array_find_with_equal_func (GPtrArray *haystack, + gconstpointer needle, + GEqualFunc equal_func, + guint *index_) +{ + guint i; + + g_return_val_if_fail (haystack != NULL, FALSE); + + if (equal_func == NULL) + equal_func = g_direct_equal; + + for (i = 0; i < haystack->len; i++) { + if (equal_func (g_ptr_array_index (haystack, i), needle)) { + if (index_ != NULL) + *index_ = i; + return TRUE; + } + } + + return FALSE; +} + +#endif diff --git a/src/libqmi-glib/qmi-helpers.h b/src/libqmi-glib/qmi-helpers.h index 38bcb4b..b954fb1 100644 --- a/src/libqmi-glib/qmi-helpers.h +++ b/src/libqmi-glib/qmi-helpers.h @@ -141,6 +141,20 @@ QMI_GDOUBLE_SWAP_LE_BE (gdouble in) #define QMI_GDOUBLE_FROM_LE(val) (QMI_GDOUBLE_TO_LE (val)) #define QMI_GDOUBLE_FROM_BE(val) (QMI_GDOUBLE_TO_BE (val)) + + +#if !GLIB_CHECK_VERSION(2,54,0) + +/* Pointer Array lookup with a GEqualFunc, imported from GLib 2.54 */ +#define g_ptr_array_find_with_equal_func qmi_ptr_array_find_with_equal_func +G_GNUC_INTERNAL +gboolean qmi_ptr_array_find_with_equal_func (GPtrArray *haystack, + gconstpointer needle, + GEqualFunc equal_func, + guint *index_); + +#endif + G_END_DECLS #endif /* _LIBQMI_GLIB_QMI_UTILS_PRIVATE_H_ */ |