From d0af224e6da2505601b9c068912903b3d32e37c6 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Thu, 19 Nov 2015 11:52:58 +0100 Subject: stringop: lenient_strcmp: Add. --- sway/stringop.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'sway') diff --git a/sway/stringop.c b/sway/stringop.c index 8d6cac2f..fe5a97ca 100644 --- a/sway/stringop.c +++ b/sway/stringop.c @@ -74,6 +74,19 @@ void strip_quotes(char *str) { *end = '\0'; } +// strcmp that also handles null pointers. +int lenient_strcmp(char *a, char *b) { + if (a == b) { + return 0; + } else if (!a) { + return -1; + } else if (!b) { + return 1; + } else { + return strcmp(a, b); + } +} + list_t *split_string(const char *str, const char *delims) { list_t *res = create_list(); char *copy = strdup(str); -- cgit v1.2.3