summaryrefslogtreecommitdiff
path: root/libiberty/strdup.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2003-04-15 03:53:53 +0000
committerDJ Delorie <dj@delorie.com>2003-04-15 03:53:53 +0000
commit4fd98ad3e5110a257df2ae36b711b25c617e642b (patch)
treea1a20d008772a71922d931b9668f91d690bb08b2 /libiberty/strdup.c
parent7c1bb6021fb2da764d8371b354008b1c7e077e2f (diff)
downloadgdb-4fd98ad3e5110a257df2ae36b711b25c617e642b.tar.gz
merge from gcc
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);
}