From 1340d926ce8abbd99bfdc89c203df4d7a33d0528 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 21 Sep 2007 13:09:23 +0200 Subject: [PATCH] add a_strcmp function --- util.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util.h b/util.h index ca9a76cf2..0f754593e 100644 --- a/util.h +++ b/util.h @@ -27,6 +27,9 @@ #include #include "config.h" +/** \brief replace \c NULL strings with emtpy strings */ +#define NONULL(x) (x ? x : "") + #define ssizeof(foo) (ssize_t)sizeof(foo) #define countof(foo) (ssizeof(foo) / ssizeof(foo[0])) @@ -118,6 +121,17 @@ static inline char *a_strdup(const char *s) return len ? p_dup(s, len + 1) : NULL; } +/** \brief \c NULL resistant strcmp. + * \param[in] a the first string. + * \param[in] b the second string. + * \return strcmp(a, b), and treats \c NULL strings like \c "" + * ones. + */ +static inline int a_strcmp(const char *a, const char *b) +{ + return strcmp(NONULL(a), NONULL(b)); +} + void die(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2))); void eprint(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2))); void uicb_spawn(Display *, DC *, awesome_config *, const char *);