strndup

Name

strndup -- return a malloc'd copy of at most the specified number of bytes of a string

Synopsis

#include <string.h>

char * strndup(const char * string, size_t n);

Description

The strndup() function shall return a malloc()'d copy of at most n bytes of string. The resultant string shall be terminated even if no NULL terminator appears before string+n.

Return Value

On success, strndup() shall return a pointer to a newly allocated block of memory containing a copy of at most n bytes of string. Otherwise, strndup() shall return NULL and set errno to indicate the error.

Errors

ENOMEM

Insufficient memory available.