From dabf9337a6acf2bb2324fb990ee03f5e8d476cdd Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Fri, 14 Sep 2018 07:53:28 +0000 Subject: [PATCH] Feature: Added helper function replace_string() --- src/util.c | 21 +++++++++++++++++++++ src/util.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/util.c b/src/util.c index a0e11b69..176e4066 100644 --- a/src/util.c +++ b/src/util.c @@ -1429,3 +1429,24 @@ int get_line(FILE *file, char *buf, size_t siz) } return 0; } + +int replace_string(char **dst, const char *src) +{ + char *n; + + if (!dst) + return -1; + + if (src) { + n = strdup(src); + if (!n) + return -1; + } else { + n = NULL; + } + + free(*dst); + *dst = n; + + return 0; +} diff --git a/src/util.h b/src/util.h index dc0c461e..393847d4 100644 --- a/src/util.h +++ b/src/util.h @@ -128,4 +128,6 @@ struct tm *localtime_r(const time_t *timep, struct tm *result); char *util_conv_string (const char *string, const char *in_charset, const char *out_charset); int get_line(FILE *file, char *buf, size_t siz); + +int replace_string(char **dst, const char *src); #endif /* __UTIL_H__ */