summaryrefslogtreecommitdiff
path: root/lib/libc/string/strdup.c
blob: 198b62cce46e672d93a392f0631fa911198f3aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "stddef.h" // for NULL

#include <stdlib.h> // for 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;
}