summaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-07-24 19:54:14 +0300
committerRan Benita <ran234@gmail.com>2012-07-27 00:27:24 +0300
commit89723b7cb7198d76990110bd3c4efae0dba97765 (patch)
treed22f80f268455be596bd52771044bb6f742560fb /src/utils.h
parent4f843c817b213e4b69ee5f3df071ebe3c917088e (diff)
downloadxorg-lib-libxkbcommon-89723b7cb7198d76990110bd3c4efae0dba97765.tar.gz
utils: add/replace string equality macros
It's more tidy and less error prone, since we use strcasecmp == 0 a lot. We replace strcmp == 0 by streq, strcasecmp == 0 by istreq, uStrCasePrefix by istreq_prefix and uDupString by strdup_safe. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/utils.h b/src/utils.h
index 89e2c13..cebdcd3 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -27,7 +27,8 @@
* software without specific, written prior permission.
\*/
-/***====================================================================***/
+#include <stdbool.h>
+#include <string.h>
/*
* We sometimes malloc strings and then expose them as const char*'s. This
@@ -36,8 +37,29 @@
*/
#define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr))
-#define uDupString(s) ((s) ? strdup(s) : NULL)
-#define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0)
+static inline bool
+streq(const char *s1, const char *s2)
+{
+ return strcmp(s1, s2) == 0;
+}
+
+static inline bool
+istreq(const char *s1, const char *s2)
+{
+ return strcasecmp(s1, s2) == 0;
+}
+
+static inline bool
+istreq_prefix(const char *s1, const char *s2)
+{
+ return strncasecmp(s1, s2, strlen(s1)) == 0;
+}
+
+static inline char *
+strdup_safe(const char *s)
+{
+ return s ? strdup(s) : NULL;
+}
/* Compiler Attributes */