The strndup function duplicates a specific number of bytes from a string. The strndup function is equivalent to the strdup function, duplicating the provided string in a new block of memory allocated as if by using malloc, with the exception that strndup copies at most size plus one bytes into the newly allocated memory, terminating the new string with a NUL character. If the length of s is larger than size, only size bytes will be duplicated. If size is larger than the length of s, all bytes in s will be copied into the new memory buffer, including the terminating NUL character. The newly created string will always be properly terminated.