summaryrefslogtreecommitdiffstats
path: root/contrib/gcclibs/libiberty/strdup.c
diff options
context:
space:
mode:
authorkan <kan@FreeBSD.org>2007-05-19 01:27:20 +0000
committerkan <kan@FreeBSD.org>2007-05-19 01:27:20 +0000
commit97ee9c3f29d2708e2a9383c5bfe5a3dd7dfe60dd (patch)
treee78bbacd6aa94e5c274d08bf2fa679b26cbf6b58 /contrib/gcclibs/libiberty/strdup.c
parent7d2f610e8aa1acfb76e67a4f7e95319fda7f50b6 (diff)
downloadFreeBSD-src-97ee9c3f29d2708e2a9383c5bfe5a3dd7dfe60dd.zip
FreeBSD-src-97ee9c3f29d2708e2a9383c5bfe5a3dd7dfe60dd.tar.gz
GCC 4.2.0 release miscellaneous support libraries.
Diffstat (limited to 'contrib/gcclibs/libiberty/strdup.c')
-rw-r--r--contrib/gcclibs/libiberty/strdup.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/contrib/gcclibs/libiberty/strdup.c b/contrib/gcclibs/libiberty/strdup.c
new file mode 100644
index 0000000..78c2093
--- /dev/null
+++ b/contrib/gcclibs/libiberty/strdup.c
@@ -0,0 +1,27 @@
+/*
+
+@deftypefn Supplemental char* strdup (const char *@var{s})
+
+Returns a pointer to a copy of @var{s} in memory obtained from
+@code{malloc}, or @code{NULL} if insufficient memory was available.
+
+@end deftypefn
+
+*/
+
+#include <ansidecl.h>
+#include <stddef.h>
+
+extern size_t strlen (const char*);
+extern PTR malloc (size_t);
+extern PTR memcpy (PTR, const PTR, size_t);
+
+char *
+strdup(const char *s)
+{
+ size_t len = strlen (s) + 1;
+ char *result = (char*) malloc (len);
+ if (result == (char*) 0)
+ return (char*) 0;
+ return (char*) memcpy (result, s, len);
+}
OpenPOWER on IntegriCloud