summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/gen/strndup.c
blob: ef9d447dfa44afb03a3308a23fc746b0e469d575 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

char*
strndup(char *p, size_t max)
{
	int n;
	char *np;

	n = strnlen(p, max);
	np = malloc(n+1);
	if(!np)
		return NULL;
	memcpy(np, p, n);
	np[n] = 0;
	return np;
}