Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/strdup.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/strdup.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/strdup.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/strdup.html on line 8
Create a duplicate of a string
#include <string.h>
char* strdup( const char* src );
- src
- The string that you want to copy.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The strdup() function creates
a duplicate of the string pointed to by src, and returns a pointer
to the new copy.
|
The strdup() function allocates the memory for the new string
by calling
malloc();
it's up to you to release the memory by calling
free(). |
A pointer to a copy of the string, or NULL if an error
occurred.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main( void )
{
char *dup;
dup = strdup( "Make a copy" );
printf( "%s\n", dup );
free (dup);
return EXIT_SUCCESS;
}
POSIX 1003.1 XSI
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
free(),
malloc(),
memmove(),
strcpy(),
strncpy(),
wcscpy(),
wcsncpy(),
wmemmove()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/strdup.html on line 148
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/strdup.html on line 148