summaryrefslogtreecommitdiff
path: root/util.c
blob: 20ad6d81f8fd125cb2952884ad6f8ab2bf02ea22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
	if (ret == NULL)
	{
		return NULL;
	}

	memcpy(ret, str, size);
	ret[size] = 0;

	return ret;
}

char *alloc_new_str(char *str)
{
	return alloc_new_str_s(str, strlen(str));
}