Description
The strdup() function allocates memory and copies into it the string addressed by s1, including the terminating null character. It is the user's responsibility to free the allocated storage by calling free().
Syntax
char *strdup(const char *s1)
Parameters
- s1
Is a null-terminated string to duplicate.
Return Values
On success, strdup() returns a pointer to a newly allocated copy of the string s1. On failure, strdup() returns a null pointer and sets errno as follows:
- ENOMEM
Insufficient memory is available to copy the string s1.