mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 15:50:36 +01:00
shared: add NM_STR_HAS_SUFFIX()
Contrary to g_str_has_suffix(), it exploits the fact the the suffix length is known at compile time. No need to call a glib function, to find out what we already know, to call strcmp(). Instead just calculate the string length and call memcmp().
This commit is contained in:
parent
d216e2f305
commit
4fab0d09a5
1 changed files with 12 additions and 1 deletions
|
|
@ -449,7 +449,7 @@ NM_G_ERROR_MSG (GError *error)
|
|||
/*****************************************************************************/
|
||||
|
||||
/* macro to return strlen() of a compile time string. */
|
||||
#define NM_STRLEN(str) ( sizeof ("" str) - 1 )
|
||||
#define NM_STRLEN(str) ( sizeof (""str"") - 1 )
|
||||
|
||||
/* returns the length of a NULL terminated array of pointers,
|
||||
* like g_strv_length() does. The difference is:
|
||||
|
|
@ -866,6 +866,17 @@ fcn (void) \
|
|||
#define NM_STR_HAS_PREFIX(str, prefix) \
|
||||
(strncmp ((str), ""prefix"", NM_STRLEN (prefix)) == 0)
|
||||
|
||||
#define NM_STR_HAS_SUFFIX(str, suffix) \
|
||||
({ \
|
||||
const char *_str = (str); \
|
||||
gsize _l = strlen (_str); \
|
||||
\
|
||||
( (_l >= NM_STRLEN (suffix)) \
|
||||
&& (memcmp (&_str[_l - NM_STRLEN (suffix)], \
|
||||
""suffix"", \
|
||||
NM_STRLEN (suffix)) == 0)); \
|
||||
})
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline GString *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue