blob: 65afd4440e4da75ea5b9aa85e1f5cc9ccf8e6792 [file] [log] [blame]
/*
* strndup.c
*/
#include <string.h>
#include <stdlib.h>
char *strndup(const char *s, size_t n)
{
int l = n > strlen(s) ? strlen(s) + 1 : n + 1;
char *d = malloc(l);
if (!d)
return NULL;
memcpy(d, s, l);
d[n] = '\0';
return d;
}