summaryrefslogtreecommitdiff
path: root/lib/libc/string/strndup.c
blob: 70e105012142a9919694e9f8eb7e4e8898516ae2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdlib.h>
#include <string.h>

char *strndup(const char *s, size_t size)
{
	char *result = malloc(size + 1);

	if (result == NULL)
		return NULL;

	memcpy(result, s, size);
	result[size] = '\0';

	return result;
}