![]() | Merged into ISO C The functionality described on this page was merged into the mainline ISO C standard as of 6/2019, seestrdup(since C23) |
Defined in header <string.h> | ||
char* strdup(constchar*str1); | (dynamic memory TR) | |
Returns a pointer to a null-terminated byte string, which is a duplicateof the string pointed to bystr1. The returned pointer must be passed tofree to avoid a memory leak.
If an error occurs, a null pointer is returned anderrno may be set.
As all functions from Dynamic Memory TR,strdup is only guaranteed to be available if__STDC_ALLOC_LIB__ is defined by the implementation and if the user defines__STDC_WANT_LIB_EXT2__ to the integer constant1 before includingstring.h.
Contents |
| str1 | - | pointer to the null-terminated byte string to duplicate |
A pointer to the newly allocated string, or a null pointer if an error occurred.
The function is identical to thePOSIX strdup.
(dynamic memory TR) | allocate a copy of a string up to specified size (function)[edit] |
(C11) | copies one string to another (function)[edit] |
| allocates memory (function)[edit] |