aboutsummaryrefslogtreecommitdiff
path: root/util/string-util.c
diff options
context:
space:
mode:
authorJani Nikula <jani@nikula.org>2015-09-25 19:48:19 +0300
committerDavid Bremner <david@tethera.net>2015-09-26 07:37:35 -0300
commitbcb695a716bf28691ac21f6faa56e93fd3210486 (patch)
treeca1fd50cda697b8bd10da947d950376e00658192 /util/string-util.c
parent23b8ed610a13802f0afa5fa70bc8faa04cf48a7f (diff)
util: add strcmp_null, a strcmp that handles NULL parameters
Add strcmp_null, a strcmp that handles NULL strings; in strcmp terms a NULL string is considered to be less than a non-NULL string.
Diffstat (limited to 'util/string-util.c')
-rw-r--r--util/string-util.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/util/string-util.c b/util/string-util.c
index 76c0b902..92af937f 100644
--- a/util/string-util.c
+++ b/util/string-util.c
@@ -223,6 +223,19 @@ parse_boolean_term (void *ctx, const char *str,
}
int
+strcmp_null (const char *s1, const char *s2)
+{
+ if (s1 && s2)
+ return strcmp (s1, s2);
+ else if (! s1 && ! s2)
+ return 0;
+ else if (s1)
+ return 1; /* s1 (non-NULL) is greater than s2 (NULL) */
+ else
+ return -1; /* s1 (NULL) is less than s2 (non-NULL) */
+}
+
+int
strcase_equal (const void *a, const void *b)
{
return strcasecmp (a, b) == 0;