summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2020-06-23 11:07:53 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2020-07-06 15:15:20 +1000
commitfe8861338242762da6a3245a106042266280714c (patch)
treebddc6826faa0d6c26ecd73bc560a6553b1c1b925
parent9b1b0c574322c0e27ab281a1aeff5499df637048 (diff)
downloadxorg-lib-libxkbcommon-fe8861338242762da6a3245a106042266280714c.tar.gz
utils: add streq_null() for streq that allows NULL values
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/utils.h8
-rw-r--r--test/utils.c6
2 files changed, 14 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
index abeaabd..67080d0 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -70,6 +70,14 @@ streq(const char *s1, const char *s2)
}
static inline bool
+streq_null(const char *s1, const char *s2)
+{
+ if (s1 == NULL || s2 == NULL)
+ return s1 == s2;
+ return streq(s1, s2);
+}
+
+static inline bool
streq_not_null(const char *s1, const char *s2)
{
if (!s1 || !s2)
diff --git a/test/utils.c b/test/utils.c
index a385a78..052289e 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -46,5 +46,11 @@ main(void)
assert(!snprintf_safe(buffer, 10, "%s", "1234567890"));
assert(snprintf_safe(buffer, 10, "%s", "123456789"));
+ assert(streq_null("foo", "foo"));
+ assert(!streq_null("foobar", "foo"));
+ assert(!streq_null("foobar", NULL));
+ assert(!streq_null(NULL, "foobar"));
+ assert(streq_null(NULL, NULL));
+
return 0;
}