Synopsis

char*strndup(constchar*s1,size_tn);

Description

strndup duplicates at most n characters from the the string pointed to
by s1 by using malloc to allocate memory for a copy of s1.

If the length of string pointed to by s1 is greater than n characters,
only n characters will be duplicated. If n is greater than the length of
string pointed to by s1, all characters in the string are copied into the
allocated array including the terminating null character.

strndup returns a pointer to the new string or a null pointer if the
new string cannot be created. The returned pointer can be passed to free.