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

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

	n = strlen(p)+1;
	if(n > max)
		n = max+1;
	np = malloc(n);
	if(!np)
		return nil;
	memmove(np, p, n);
	np[n-1] = 0;
	return np;
}