binutils-gdb/libiberty/strdup.c

22 lines
388 B
C
Raw Normal View History

2001-09-26 20:45:50 +02:00
/*
@deftypefn Supplemental char* strdup (const char *@var{s})
Returns a pointer to a copy of @var{s} in memory obtained from
2001-10-08 00:42:23 +02:00
@code{malloc}, or @code{NULL} if insufficient memory was available.
2001-09-26 20:45:50 +02:00
@end deftypefn
*/
1999-05-03 09:29:11 +02: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;
}