strdup() — Duplicate a String

Format

#include <string.h>

char *strdup(const char *string);

General Description

The strdup() function creates a duplicate of the string pointed to by string.
Note: Use of this function requires that an environment has been set up by using the __cinit() function. When the function is called, GPR 12 must contain the environment token created by the __cinit() call.

Returned Value

If successful, strdup() returns a pointer to a new string which is a duplicate of string.

Otherwise, strdup() returns a NULL pointer.

Note: The caller of strdup() should free the storage obtained for the string.

Related Information