old-cross-binutils/libiberty/strdup.c

22 lines
388 B
C
Raw Normal View History

2001-09-26 18:45:50 +00:00
/*
@deftypefn Supplemental char* strdup (const char *@var{s})
Returns a pointer to a copy of @var{s} in memory obtained from
2001-10-07 22:42:23 +00:00
@code{malloc}, or @code{NULL} if insufficient memory was available.
2001-09-26 18:45:50 +00:00
@end deftypefn
*/
1999-05-03 07:29:11 +00:00
char *
strdup(s)
char *s;
{
char *result = (char*)malloc(strlen(s) + 1);
if (result == (char*)0)
return (char*)0;
strcpy(result, s);
return result;
}