strdup

Creates a duplicate of a string and returns a pointer to the new copy.

Library:LibC
Classification:POSIX
Service:Characters and Strings

Syntax

  #include <string.h> 
   
  char *strdup (
     const char   *src);
  

Parameters

src

(IN) Points to the string to be copied.

Return Values

If successful, returns a pointer to the new copy of the string; otherwise, returns a NULL pointer and sets errno to the following:

Decimal

Constant

Description

5

ENOMEM

Sufficient storage space is not available.

Remarks

The memory for the new string is obtained by using the malloc function and can be freed using the free function.

See Also

strcpy