/* * strndup() - Duplicate a string of length up to the * specified maximum. * * Dan Cross */ #include #include #include char * strndup(const char *str, size_t maxlen) { char *p; size_t len; len = strlen(str); if (len > maxlen) len = maxlen; p = malloc(len + 1); if (p == NULL) return(NULL); strlcpy(p, str, len); return(p); }