strdup(), strndup()

duplicate string 

Function


SYNOPSIS

#include <string.h>

char *strdup(const char *s1);

char *strndup(const char *s1, size_t size);


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().

The strndup() function copies at most size characters from the string s1 always NUL terminating the copied string.


PARAMETERS

s1 

Is a null-terminated string to duplicate.

size 

Copy at most size characters. The resulting string will be NUL perminated.


RETURN VALUES

On success, strdup() and strndup() return a pointer to a newly allocated copy of the string s1. On failure, strdup() and strndup() return a null pointer and sets errno as follows:

ENOMEM 

Insufficient memory is available to copy the string s1.


CONFORMANCE

strdup() comforms to UNIX 98.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
calloc(), free(), malloc(), strcpy(), strlcpy()


PTC MKS Toolkit 10.1 Documentation Build 15.