Add a "smart strdup" helper named copy_string()

If the string is non-NULL, copy it, otherwise return NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-02 21:05:22 -07:00
parent 56501dda1e
commit 2cfe97e4dd
2 changed files with 17 additions and 14 deletions

5
dive.h
View file

@ -29,6 +29,11 @@ static inline int same_string(const char *a, const char *b)
return !strcmp(a ?: "", b ?: "");
}
static inline char *copy_string(const char *s)
{
return s ? strdup(s) : NULL;
}
#include <libxml/tree.h>
#include <libxslt/transform.h>