ref: e1cd22504e26d0a732a4219d38d6e5fe3e03aa21
dir: /sys/src/ape/lib/ap/gen/strndup.c/
#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;
}