summaryrefslogtreecommitdiff
path: root/libiberty/strdup.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-15 02:11:43 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-15 02:11:43 +0000
commit68acb842e92277cfb4b72499f3734c3bab021a92 (patch)
tree0d692d5314c2000f34e52fe72ce53d5cb41a9b1e /libiberty/strdup.c
parentc26210535efc12fa30997a2f42deadb5c871de9e (diff)
downloadgcc-68acb842e92277cfb4b72499f3734c3bab021a92.tar.gz
* strdup.c (strdup): Tweak implementation to use memcpy.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@65616 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/strdup.c')
-rw-r--r--libiberty/strdup.c21
1 files changed, 16 insertions, 5 deletions
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);
}