summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2020-04-15 20:52:23 +0100
committerFreeArtMan <dos21h@gmail.com>2020-04-15 20:52:23 +0100
commitef29d288ed57250b399d6a95cf26a40d4e33794e (patch)
tree10b124d73cc6bef42fba56abdf8f65fc277bcc8e /util.c
parent6c44c2e89000444b1bdf790452fd1b92d121ed06 (diff)
downloadihe-master.tar.gz
ihe-master.zip
Open file with space in filenameHEADmaster
Diffstat (limited to 'util.c')
-rw-r--r--util.c33
1 files changed, 33 insertions, 0 deletions
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));
+}