X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libiberty%2Fstrdup.c;h=78c2093b61a3d05c758c9c14814ef38eb468633b;hb=HEAD;hp=a01cedfbee03359de1dda64646283dba5f7f0acc;hpb=bd7ce1bbb2ea47e045e6dd755cf16f05a2555309;p=pf3gnuchains%2Fpf3gnuchains3x.git diff --git a/libiberty/strdup.c b/libiberty/strdup.c index a01cedfbee..78c2093b61 100644 --- a/libiberty/strdup.c +++ b/libiberty/strdup.c @@ -3,19 +3,25 @@ @deftypefn Supplemental char* strdup (const char *@var{s}) Returns a pointer to a copy of @var{s} in memory obtained from -@code{malloc}, or NULL if insufficient memory was available. +@code{malloc}, or @code{NULL} if insufficient memory was available. @end deftypefn */ +#include +#include + +extern size_t strlen (const char*); +extern PTR malloc (size_t); +extern PTR memcpy (PTR, const PTR, size_t); + char * -strdup(s) - char *s; +strdup(const char *s) { - char *result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; + size_t len = strlen (s) + 1; + char *result = (char*) malloc (len); + if (result == (char*) 0) + return (char*) 0; + return (char*) memcpy (result, s, len); }