strdup(3C) DG/UX 4.30 strdup(3C)
NAME
strdup - Copy a string to an allocated area of memory.
SYNOPSIS
char *strdup(), *newstr, *oldstr;
newstr = strdup(oldstr);
where old_str is a pointer to a character array.
new_str is a pointer to an allocated area containing
the new copy of the string.
DESCRIPTION
The strdup function first allocates enough memory with
malloc3c to hold a string, then moves a copy of the string
into the allocated area. The function then returns a
pointer to the area that contains the copy of the string.
The include file string.h defines this function.
RETURNS
The strdup function returns a pointer to the allocated area
that contains the string copy. It returns a null pointer if
there is no allocatable memory.
SEE ALSO
See also the malloc(3c) function.
EXAMPLE
/* Program test for the strdup() function */
#include <stdio.h>
#include <string.h>
char *strdup(), *p;
void free();
main() {
p = strdup("Testing strdup.\n");
fputs(p, stdout);
free(p);
return 0;
}
A call to this program generates the output
Testing strdup.
Licensed material--property of copyright holder(s) Page 1