Added a null-safe strdup variant

This commit is contained in:
Martin Willi
2011-01-05 16:46:02 +01:00
parent b0892d094c
commit 1038d9fee5
7 changed files with 13 additions and 8 deletions
+1 -1
View File
@@ -127,7 +127,7 @@ static section_t *section_create(char *name)
{
section_t *this;
INIT(this,
.name = name ? strdup(name) : NULL,
.name = strdupnull(name),
.sections = linked_list_create(),
.kv = linked_list_create(),
);
+5
View File
@@ -71,6 +71,11 @@
*/
#define strncaseeq(x,y,len) (strncasecmp(x, y, len) == 0)
/**
* NULL-safe strdup variant
*/
#define strdupnull(x) ({ char *_x = x; _x ? strdup(_x) : NULL; })
/**
* Macro compares two binary blobs for equality
*/