fxlibc/src/libc/string/strndup.c

16 lines
220 B
C

#include <string.h>
#include <stdlib.h>
char *strndup(const char *s, size_t n)
{
size_t len = strnlen(s, n) + 1;
char *copy = malloc(len);
if(copy) {
memcpy(copy, s, len);
copy[len - 1] = 0;
}
return copy;
}