Automatic date update in version.in
[binutils-gdb.git] / libiberty / strdup.c
blob8a4188eadfbcdf487fac3d28a56e5296d2548087
1 /*
3 @deftypefn Supplemental char* strdup (const char *@var{s})
5 Returns a pointer to a copy of @var{s} in memory obtained from
6 @code{malloc}, or @code{NULL} if insufficient memory was available.
8 @end deftypefn
12 #include <ansidecl.h>
13 #include <stddef.h>
15 extern size_t strlen (const char*);
16 extern void *malloc (size_t);
17 extern void *memcpy (void *, const void *, size_t);
19 char *
20 strdup(const char *s)
22 size_t len = strlen (s) + 1;
23 char *result = (char*) malloc (len);
24 if (result == (char*) 0)
25 return (char*) 0;
26 return (char*) memcpy (result, s, len);