shared: add helper macros nm_str_not_empty() and nm_strdup_not_empty()

This commit is contained in:
Thomas Haller 2016-09-02 14:58:56 +02:00
parent 2724ec53b7
commit 3227b9017b

View file

@ -302,6 +302,22 @@ _NM_IN_STRSET_streq (const char *x, const char *s)
/*****************************************************************************/
#define nm_str_not_empty(str) \
({ \
/* implemented as macro to preserve constness */ \
typeof (str) __str = (str); \
_nm_unused const char *__str_type_check = __str; \
((__str && __str[0]) ? __str : ((char *) NULL)); \
})
static inline char *
nm_strdup_not_empty (const char *str)
{
return str && str[0] ? g_strdup (str) : NULL;
}
/*****************************************************************************/
#define NM_PRINT_FMT_QUOTED(cond, prefix, str, suffix, str_else) \
(cond) ? (prefix) : "", \
(cond) ? (str) : (str_else), \