summaryrefslogtreecommitdiff
path: root/lib/libc/string/strdup.c
blob: 97b5d712e2c5167bb13147a5a9556ac8ddb2cc50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdlib.h> // for NULL, malloc
#include <string.h> // for memcpy, strlen, size_t, strdup

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