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() and _fstrdup() functions create 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 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:

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

See also:

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

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 naming conventions.

Systems:

strdup()
All (except DOS/PM)
_strdup()
All (except DOS/PM)
_fstrdup()
All (except Netware, DOS/PM)