2.2.20 char * strdup

char * strdup(const char *s1)

The strdup() function allocates memory and copies into it the string addressed by s1, including the terminating null character.

CAUTION:

The strdup() function calls malloc() to allocate the memory for the duplicated string! The user is responsible for freeing the memory by calling free().

Remember:

The strdup() function returns a pointer to the resulting string dest. If malloc() cannot allocate enough storage for the string, strdup() will return NULL.

CAUTION:

Be sure to check the return value of the strdup() function to make sure that the function has succeeded in allocating the memory!