util: introduce streq_ptr() for comparing strings or their pointers

This commit is contained in:
Lennart Poettering 2010-04-10 04:38:14 +02:00
parent 2e317f525f
commit e05797fba2
2 changed files with 15 additions and 0 deletions

13
util.c
View File

@ -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;

2
util.h
View File

@ -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)))