util: introduce streq_ptr() for comparing strings or their pointers
This commit is contained in:
parent
2e317f525f
commit
e05797fba2
13
util.c
13
util.c
|
@ -42,6 +42,19 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "strv.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) {
|
usec_t now(clockid_t clock_id) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|
||||||
|
|
2
util.h
2
util.h
|
@ -51,6 +51,8 @@ struct timeval *timeval_store(struct timeval *tv, usec_t u);
|
||||||
|
|
||||||
#define streq(a,b) (strcmp((a),(b)) == 0)
|
#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 new(t, n) ((t*) malloc(sizeof(t)*(n)))
|
||||||
|
|
||||||
#define new0(t, n) ((t*) calloc((n), sizeof(t)))
|
#define new0(t, n) ((t*) calloc((n), sizeof(t)))
|
||||||
|
|
Loading…
Reference in a new issue