ref: 5a059477f8066f25ece1ba2b8c49ab8ea24d19de
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;
}