aboutsummaryrefslogtreecommitdiffstats
path: root/sway/stringop.c
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-11-19 11:52:58 +0100
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-11-21 22:22:09 +0100
commitd0af224e6da2505601b9c068912903b3d32e37c6 (patch)
tree7db38e658ece1c7b65e9b4e57e7b2a511076f997 /sway/stringop.c
parentlist: Add list_seq_find. (diff)
downloadsway-d0af224e6da2505601b9c068912903b3d32e37c6.tar.gz
sway-d0af224e6da2505601b9c068912903b3d32e37c6.tar.zst
sway-d0af224e6da2505601b9c068912903b3d32e37c6.zip
stringop: lenient_strcmp: Add.
Diffstat (limited to 'sway/stringop.c')
-rw-r--r--sway/stringop.c13
1 files changed, 13 insertions, 0 deletions
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) {
74 *end = '\0'; 74 *end = '\0';
75} 75}
76 76
77// strcmp that also handles null pointers.
78int lenient_strcmp(char *a, char *b) {
79 if (a == b) {
80 return 0;
81 } else if (!a) {
82 return -1;
83 } else if (!b) {
84 return 1;
85 } else {
86 return strcmp(a, b);
87 }
88}
89
77list_t *split_string(const char *str, const char *delims) { 90list_t *split_string(const char *str, const char *delims) {
78 list_t *res = create_list(); 91 list_t *res = create_list();
79 char *copy = strdup(str); 92 char *copy = strdup(str);