diff --git a/src/misc.c b/src/misc.c index b2856051..0abd07f1 100644 --- a/src/misc.c +++ b/src/misc.c @@ -261,6 +261,15 @@ safe_hextou64(const char *str, uint64_t *val) return 0; } +char * +safe_strdup(const char *str) +{ + if (str == NULL) + return NULL; + + return strdup(str); +} + /* Key/value functions */ struct keyval * diff --git a/src/misc.h b/src/misc.h index 7aa615c1..148fd4b2 100644 --- a/src/misc.h +++ b/src/misc.h @@ -41,6 +41,8 @@ safe_atou64(const char *str, uint64_t *val); int safe_hextou64(const char *str, uint64_t *val); +char * +safe_strdup(const char *str); /* Key/value functions */ struct keyval *