From 45d6baac4d371d4ed709babcdd2d43438c438bb7 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 20 May 2016 20:44:05 +0200 Subject: [PATCH] shared: backport g_strv_contains() --- shared/nm-utils/nm-glib.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/shared/nm-utils/nm-glib.h b/shared/nm-utils/nm-glib.h index 46a8bb2d9..a014e2606 100644 --- a/shared/nm-utils/nm-glib.h +++ b/shared/nm-utils/nm-glib.h @@ -394,4 +394,34 @@ g_steal_pointer (gpointer pp) (0 ? (*(pp)) : (g_steal_pointer) (pp)) #endif +#if !GLIB_CHECK_VERSION(2, 44, 0) || defined (NM_GLIB_COMPAT_H_TEST) +static inline gboolean +_nm_g_strv_contains (const gchar * const *strv, + const gchar *str) +{ + g_return_val_if_fail (strv != NULL, FALSE); + g_return_val_if_fail (str != NULL, FALSE); + + for (; *strv != NULL; strv++) { + if (g_str_equal (str, *strv)) + return TRUE; + } + + return FALSE; +} +#endif +#if !GLIB_CHECK_VERSION(2, 44, 0) +#define g_strv_contains(strv, str) \ + G_GNUC_EXTENSION ({ \ + _nm_g_strv_contains (strv, str); \ + }) +#else +#define g_strv_contains(strv, str) \ + G_GNUC_EXTENSION ({ \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + (g_strv_contains) ((strv), (str)); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ + }) +#endif + #endif /* __NM_GLIB_H__ */