From 12fa6375acb536e61f41c006fc783e5e8f0c7a92 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 21 Feb 2020 17:00:59 +0100 Subject: Add safe_strdup() to utils --- libcrystfel/src/utils.c | 7 +++++++ libcrystfel/src/utils.h | 1 + 2 files changed, 8 insertions(+) diff --git a/libcrystfel/src/utils.c b/libcrystfel/src/utils.c index de1dc2f4..0c01c069 100644 --- a/libcrystfel/src/utils.c +++ b/libcrystfel/src/utils.c @@ -503,6 +503,13 @@ char *check_prefix(char *prefix) } +char *safe_strdup(const char *in) +{ + if ( in == NULL ) return NULL; + return strdup(in); +} + + char *safe_basename(const char *in) { int i; diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h index b2694f2a..f406ef6c 100644 --- a/libcrystfel/src/utils.h +++ b/libcrystfel/src/utils.h @@ -222,6 +222,7 @@ extern pthread_mutex_t stderr_lock; extern char *check_prefix(char *prefix); extern char *safe_basename(const char *in); +extern char *safe_strdup(const char *in); extern void strip_extension(char *bfn); extern char *load_entire_file(const char *filename); -- cgit v1.2.3