strdup()
QNX SDP8.0C Library ReferenceAPIDeveloper
Create a duplicate of a string
Synopsis:
#include <string.h>
char* strdup( const char* src );
Arguments:
- src
- The string that you want to copy.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The strdup() function creates a duplicate of the string pointed to by src, and returns a pointer to the new copy.
Returns:
A pointer to a copy of the string, or NULL if an error occurred (errno) is set.
Errors:
- ENOMEM
- Not enough memory.
Examples:
#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;
}
Classification:
Safety: | |
---|---|
Cancellation point | No |
Signal handler | No |
Thread | Yes |
Page updated: