summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-08-01 20:44:08 +0200
committerThomas Haller <thaller@redhat.com>2022-08-11 18:10:12 +0200
commitdced08e3b045d72d5b6c5cdd1e9b5de552d2dfea (patch)
treed6585e2ba1000b48cc3788fd14e038cc6aa4ef67
parent47d2f43d870362911e80f51dd00f247b85128ba8 (diff)
glib-aux: add nm_g_hash_table_contains_any() helper
(cherry picked from commit e0fc8a11d5310303e680f101604291a4139317dd)
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index 596eaccd05..0589eeacad 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -2321,6 +2321,25 @@ nm_g_hash_table_contains(GHashTable *hash, gconstpointer key)
return hash ? g_hash_table_contains(hash, key) : FALSE;
}
+#define nm_g_hash_table_contains_any(hash, ...) \
+ ({ \
+ GHashTable *const _hash = (hash); \
+ gconstpointer const _keys[] = {__VA_ARGS__}; \
+ int _i_key; \
+ gboolean _contains = FALSE; \
+ \
+ if (_hash) { \
+ for (_i_key = 0; _i_key < (int) G_N_ELEMENTS(_keys); _i_key++) { \
+ if (g_hash_table_contains(_hash, _keys[_i_key])) { \
+ _contains = TRUE; \
+ break; \
+ } \
+ } \
+ } \
+ \
+ _contains; \
+ })
+
static inline gboolean
nm_g_hash_table_remove(GHashTable *hash, gconstpointer key)
{