merge from gcc
[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
DD
12#include <ansidecl.h>
13#ifdef ANSI_PROTOTYPES
14#include <stddef.h>
15#else
16#define size_t unsigned long
17#endif
18
19extern size_t strlen PARAMS ((const char*));
20extern PTR malloc PARAMS ((size_t));
21extern PTR memcpy PARAMS ((PTR, const PTR, size_t));
22
252b5132
RH
23char *
24strdup(s)
211333f6 25 const char *s;
252b5132 26{
eec539c7
DD
27 size_t len = strlen (s) + 1;
28 char *result = (char*) malloc (len);
29 if (result == (char*) 0)
30 return (char*) 0;
31 return (char*) memcpy (result, s, len);
252b5132 32}
This page took 0.283629 seconds and 4 git commands to generate.