From c030a850ba59fbcdf796abfe48b2f220933c52c0 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Sat, 1 Aug 2015 00:23:47 +0900 Subject: busctl: add and use strcmp_ptr() In member_compare_func(), it compares interface, type and name of members. But as it can contain NULL pointer, it needs to check them before calling strcmp(). So make it as a separate strcmp_ptr function (named after streq_ptr) so that it can be used by others. Also let streq_ptr() to use it in order to make the code simpler. --- src/basic/util.c | 20 +++++++++++++------- src/basic/util.h | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/basic') diff --git a/src/basic/util.c b/src/basic/util.c index 1c15fbc172..a968e2156d 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -115,17 +115,23 @@ size_t page_size(void) { return pgsz; } -bool streq_ptr(const char *a, const char *b) { - - /* Like streq(), but tries to make sense of NULL pointers */ +int strcmp_ptr(const char *a, const char *b) { + /* Like strcmp(), but tries to make sense of NULL pointers */ if (a && b) - return streq(a, b); + return strcmp(a, b); - if (!a && !b) - return true; + if (!a && b) + return -1; - return false; + if (a && !b) + return 1; + + return 0; +} + +bool streq_ptr(const char *a, const char *b) { + return strcmp_ptr(a, b) == 0; } char* endswith(const char *s, const char *postfix) { diff --git a/src/basic/util.h b/src/basic/util.h index c2e5cc610b..05ddf14780 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -71,6 +71,7 @@ size_t page_size(void) _pure_; #define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0) bool streq_ptr(const char *a, const char *b) _pure_; +int strcmp_ptr(const char *a, const char *b) _pure_; #define new(t, n) ((t*) malloc_multiply(sizeof(t), (n))) -- cgit v1.2.3-54-g00ecf