summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}