aboutsummaryrefslogtreecommitdiff
path: root/src/lib/string.c
blob: 2e71489ff60cb14be2edf8fb828b8c44fac476ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string.h>
#include <stddef.h>
#include <stdlib.h>

char *strdup(const char *s)
{
	size_t sz = strlen(s) + 1;
	char *d = malloc(sz);
	if (d)
		memcpy(d, s, sz);
	return d;
}

char *strconcat(const char *s1, const char *s2)
{
	size_t sz_1 = strlen(s1);
	size_t sz_2 = strlen(s2);
	char *d = malloc(sz_1 + sz_2 + 1);
	if (d) {
		memcpy(d, s1, sz_1);
		memcpy(d + sz_1, s2, sz_2 + 1);
	}
	return d;
}