init version.
[bush.git] / lib / sh / strdup.c
blob38cde7a4bbf33a46613284bc2cdf08dc41dd934b
1 /* strdup - return a copy of a string in newly-allocated memory. */
3 /* Copyright (C) 2013 Free Software Foundation, Inc.
5 This file is part of GNU Bush, the Bourne Again SHell.
7 Bush is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bush is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bush. If not, see <http://www.gnu.org/licenses/>.
22 #include <config.h>
24 /* Get specification. */
25 #include <string.h>
26 #include <stdlib.h>
28 /* Duplicate S, returning an identical malloc'd string. */
29 char *
30 strdup (s)
31 const char *s;
33 size_t len;
34 void *new;
36 len = strlen (s) + 1;
37 if ((new = malloc (len)) == NULL)
38 return NULL;
40 memcpy (new, s, len);
41 return ((char *)new);