diff options
author | FreeArtMan <dos21h@gmail.com> | 2020-04-15 20:52:23 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2020-04-15 20:52:23 +0100 |
commit | ef29d288ed57250b399d6a95cf26a40d4e33794e (patch) | |
tree | 10b124d73cc6bef42fba56abdf8f65fc277bcc8e /util.c | |
parent | 6c44c2e89000444b1bdf790452fd1b92d121ed06 (diff) | |
download | ihe-master.tar.gz ihe-master.zip |
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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)); +} |