#include #include 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; }