strdup() — Duplicate a string

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define  _XOPEN_SOURCE_EXTENDED 1
#include <string.h>

char *strdup(const char *string);

General description

The strdup() function creates a duplicate of the string pointed to by string.

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.
Error Code
Description
ENOMEM
Insufficient storage space is available.

Related information