diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2020-06-23 11:07:53 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2020-07-06 15:15:20 +1000 |
commit | fe8861338242762da6a3245a106042266280714c (patch) | |
tree | bddc6826faa0d6c26ecd73bc560a6553b1c1b925 | |
parent | 9b1b0c574322c0e27ab281a1aeff5499df637048 (diff) | |
download | xorg-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.h | 8 | ||||
-rw-r--r-- | test/utils.c | 6 |
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; } |