[Previous]
[Contents]
[Next]

strdup(), _strdup(), _fstrdup()

create a duplicate of a string

Synopsis:

#include <string.h>

char *strdup( const char *src );
char *_strdup( const char *src );
char __far *_fstrdup( const char __far *src );

Description:

The strdup() function creates a duplicate of the string pointed to by src, and returns a pointer to the new copy. For strdup(), the memory for the new string is obtained by using the malloc() function, and can be freed using the free() function. For _fstrdup(), the memory for the new string is obtained by using the _fmalloc() function, and can be freed using the _ffree() function.

The _strdup() function is identical to strdup(). Use _strdup() for ANSI/ISO naming conventions.

The _fstrdup() function is a data-model-independent form of the strdup() function that accepts far pointer arguments. It is most useful in mixed memory model applications.

Returns:

A pointer to the new copy of the string if successful, otherwise NULL.

Examples:

#include <stdio.h>
#include <string.h>

void main()
  {
    char *dup;

    dup = strdup( "Make a copy" );
    printf( "%s\n", dup );
  }

Classification:

WATCOM

_strdup() conforms to ANSI/ISO naming conventions.

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

free(), malloc(), strcpy(), strncpy()


[Previous]
[Contents]
[Next]