From: Lennart Poettering Date: Sat, 10 Apr 2010 02:38:14 +0000 (+0200) Subject: util: introduce streq_ptr() for comparing strings or their pointers X-Git-Tag: v1~588 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=e05797fba258d7a58987cc8870fae6e34b94fe46 util: introduce streq_ptr() for comparing strings or their pointers --- diff --git a/util.c b/util.c index b4d6eefbd..3fe59c8eb 100644 --- a/util.c +++ b/util.c @@ -42,6 +42,19 @@ #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 30a0616d5..4881c981b 100644 --- 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)))