* elf32-m32c.c (m32c_offset_for_reloc): Fix local symbol
[deliverable/binutils-gdb.git] / libiberty / strdup.c
CommitLineData
39423523
DD
1/*
2
3@deftypefn Supplemental char* strdup (const char *@var{s})
4
5Returns a pointer to a copy of @var{s} in memory obtained from
99b58139 6@code{malloc}, or @code{NULL} if insufficient memory was available.
39423523
DD
7
8@end deftypefn
9
10*/
11
eec539c7 12#include <ansidecl.h>
eec539c7 13#include <stddef.h>
eec539c7 14
1e45deed
DD
15extern size_t strlen (const char*);
16extern PTR malloc (size_t);
17extern PTR memcpy (PTR, const PTR, size_t);
eec539c7 18
252b5132 19char *
1e45deed 20strdup(const char *s)
252b5132 21{
eec539c7
DD
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);
252b5132 27}
This page took 0.354471 seconds and 4 git commands to generate.