chiark / gitweb /
util: introduce streq_ptr() for comparing strings or their pointers
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 02:38:14 +0000 (04:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Apr 2010 02:38:14 +0000 (04:38 +0200)
util.c
util.h

diff --git a/util.c b/util.c
index b4d6eefbd265f160eddfe38e0f07f88954aafc4d..3fe59c8ebba4b1a425bb0e4ee6bd2860d2715f9b 100644 (file)
--- a/util.c
+++ b/util.c
 #include "log.h"
 #include "strv.h"
 
+bool streq_ptr(const char *a, const char *b) {
+
+        /* Like streq(), but tries to make sense of NULL pointers */
+
+        if (a && b)
+                return streq(a, b);
+
+        if (!a && !b)
+                return true;
+
+        return false;
+}
+
 usec_t now(clockid_t clock_id) {
         struct timespec ts;
 
diff --git a/util.h b/util.h
index 30a0616d542060d8c98aa3028c0eab95a914d727..4881c981b9dedf1a6d41dd58127e7d37aa71f2f2 100644 (file)
--- a/util.h
+++ b/util.h
@@ -51,6 +51,8 @@ struct timeval *timeval_store(struct timeval *tv, usec_t u);
 
 #define streq(a,b) (strcmp((a),(b)) == 0)
 
+bool streq_ptr(const char *a, const char *b);
+
 #define new(t, n) ((t*) malloc(sizeof(t)*(n)))
 
 #define new0(t, n) ((t*) calloc((n), sizeof(t)))