From ef29d288ed57250b399d6a95cf26a40d4e33794e Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Wed, 15 Apr 2020 20:52:23 +0100 Subject: Open file with space in filename --- util.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 util.c (limited to 'util.c') diff --git a/util.c b/util.c new file mode 100644 index 0000000..ebd264c --- /dev/null +++ b/util.c @@ -0,0 +1,33 @@ +#include "util.h" + +char *alloc_new_str_s(char *str, size_t size) +{ + char *ret = NULL; + + if (str == NULL) + { + return NULL; + } + + //1MB is enought + if (size > (1024*1024)) + { + return NULL; + } + + ret = malloc(size+1); //extra for 1 zero at then end + if (ret == NULL) + { + return NULL; + } + + memcpy(ret, str, size); + ret[size] = 0; //add zero at the end + + return ret; +} + +char *alloc_new_str(char *str) +{ + return alloc_new_str_s(str, strlen(str)); +} -- cgit v1.2.3