1 /* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004 Free Software
2 Foundation, Inc.
3
4 This file is part of the GNU C Library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #include <sys/cdefs.h>
20 __RCSID("$NetBSD: strdup.c,v 1.2 2016/05/17 14:00:09 christos Exp $");
21
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #ifndef _LIBC
28 /* Get specification. */
29 # include "strdup.h"
30 #endif
31
32 #include <stdlib.h>
33 #include <string.h>
34
35 #undef __strdup
36 #undef strdup
37
38 #ifndef weak_alias
39 # define __strdup strdup
40 #endif
41
42 /* Duplicate S, returning an identical malloc'd string. */
43 char *
__strdup(const char * s)44 __strdup (const char *s)
45 {
46 size_t len = strlen (s) + 1;
47 void *new = malloc (len);
48
49 if (new == NULL)
50 return NULL;
51
52 return (char *) memcpy (new, s, len);
53 }
54 #ifdef libc_hidden_def
55 libc_hidden_def (__strdup)
56 #endif
57 #ifdef weak_alias
58 weak_alias (__strdup, strdup)
59 #endif
60