#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)); }