summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-31 09:20:23 +0200
committerThomas Haller <thaller@redhat.com>2020-08-05 10:22:11 +0200
commita46940d0d7d5097143864f84844b67cdbb953061 (patch)
tree22a6fcc29e26d48b0524114b287d882b18019b59
parent3b64d88a935718ae9813641bbac440fc8eb34441 (diff)
downloadNetworkManager-a46940d0d7d5097143864f84844b67cdbb953061.tar.gz
shared: add NM_STR_HAS_SUFFIX_ASCII_CASE() macro
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index c9862be423..c917272384 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -1241,6 +1241,20 @@ _NM_IN_STRSET_ASCII_CASE_op_streq (const char *x, const char *s)
#define NM_IN_STRSET_ASCII_CASE(x, ...) _NM_IN_STRSET_EVAL_N(||, _NM_IN_STRSET_ASCII_CASE_op_streq, x, NM_NARG (__VA_ARGS__), __VA_ARGS__)
+#define NM_STR_HAS_SUFFIX_ASCII_CASE(str, suffix) \
+ ({ \
+ const char *const _str_has_suffix = (str); \
+ size_t _l; \
+ \
+ nm_assert (strlen (suffix) == NM_STRLEN (suffix)); \
+ \
+ ( _str_has_suffix \
+ && ((_l = strlen (_str_has_suffix)) >= NM_STRLEN (suffix)) \
+ && (g_ascii_strncasecmp (&_str_has_suffix[_l - NM_STRLEN (suffix)], \
+ ""suffix"", \
+ NM_STRLEN (suffix)) == 0)); \
+ })
+
/*****************************************************************************/
#define nm_g_slice_free(ptr) \