diff options
author | Roger Sayle <roger@eyesopen.com> | 2003-04-15 02:11:43 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2003-04-15 02:11:43 +0000 |
commit | 88702c45a68e768f8d5537f2c6c77c9c7b7e6d58 (patch) | |
tree | 0d692d5314c2000f34e52fe72ce53d5cb41a9b1e /libiberty | |
parent | f4e929877c7e155de2f729c3330353762ce1b0ed (diff) | |
download | gcc-88702c45a68e768f8d5537f2c6c77c9c7b7e6d58.tar.gz |
* strdup.c (strdup): Tweak implementation to use memcpy.
From-SVN: r65616
Diffstat (limited to 'libiberty')
-rw-r--r-- | libiberty/ChangeLog | 4 | ||||
-rw-r--r-- | libiberty/strdup.c | 21 |
2 files changed, 20 insertions, 5 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index ec69410e2f7..679b382e051 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,7 @@ +2003-04-14 Roger Sayle <roger@eyesopen.com> + + * strdup.c (strdup): Tweak implementation to use memcpy. + 2003-04-14 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> * configure.in (HAVE_UINTPTR_T): Always define. diff --git a/libiberty/strdup.c b/libiberty/strdup.c index 49233ba7aac..071a4a401af 100644 --- a/libiberty/strdup.c +++ b/libiberty/strdup.c @@ -9,13 +9,24 @@ Returns a pointer to a copy of @var{s} in memory obtained from */ +#include <ansidecl.h> +#ifdef ANSI_PROTOTYPES +#include <stddef.h> +#else +#define size_t unsigned long +#endif + +extern size_t strlen PARAMS ((const char*)); +extern PTR malloc PARAMS ((size_t)); +extern PTR memcpy PARAMS ((PTR, const PTR, size_t)); + char * strdup(s) 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); } |