1*a1acfa9bSespie /* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004 Free Software
2*a1acfa9bSespie Foundation, Inc.
3*a1acfa9bSespie
4*a1acfa9bSespie This file is part of the GNU C Library.
5840175f0Skstailey
6840175f0Skstailey This program is free software; you can redistribute it and/or modify
7840175f0Skstailey it under the terms of the GNU General Public License as published by
8840175f0Skstailey the Free Software Foundation; either version 2, or (at your option)
9840175f0Skstailey any later version.
10840175f0Skstailey
11840175f0Skstailey This program is distributed in the hope that it will be useful,
12840175f0Skstailey but WITHOUT ANY WARRANTY; without even the implied warranty of
13840175f0Skstailey MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14840175f0Skstailey GNU General Public License for more details.
15840175f0Skstailey
16*a1acfa9bSespie You should have received a copy of the GNU General Public License along
17*a1acfa9bSespie with this program; if not, write to the Free Software Foundation,
183fb98d4aSespie Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19840175f0Skstailey
20*a1acfa9bSespie #ifdef HAVE_CONFIG_H
21840175f0Skstailey # include <config.h>
22840175f0Skstailey #endif
23840175f0Skstailey
24*a1acfa9bSespie #ifndef _LIBC
25*a1acfa9bSespie /* Get specification. */
26*a1acfa9bSespie # include "strdup.h"
27840175f0Skstailey #endif
28840175f0Skstailey
29*a1acfa9bSespie #include <stdlib.h>
30*a1acfa9bSespie #include <string.h>
31840175f0Skstailey
32*a1acfa9bSespie #undef __strdup
33*a1acfa9bSespie #undef strdup
34*a1acfa9bSespie
35*a1acfa9bSespie #ifndef weak_alias
36*a1acfa9bSespie # define __strdup strdup
37*a1acfa9bSespie #endif
38*a1acfa9bSespie
39*a1acfa9bSespie /* Duplicate S, returning an identical malloc'd string. */
40840175f0Skstailey char *
__strdup(const char * s)41*a1acfa9bSespie __strdup (const char *s)
42840175f0Skstailey {
43*a1acfa9bSespie size_t len = strlen (s) + 1;
44*a1acfa9bSespie void *new = malloc (len);
45840175f0Skstailey
46*a1acfa9bSespie if (new == NULL)
47*a1acfa9bSespie return NULL;
48*a1acfa9bSespie
49*a1acfa9bSespie return (char *) memcpy (new, s, len);
50840175f0Skstailey }
51*a1acfa9bSespie #ifdef libc_hidden_def
52*a1acfa9bSespie libc_hidden_def (__strdup)
53*a1acfa9bSespie #endif
54*a1acfa9bSespie #ifdef weak_alias
55*a1acfa9bSespie weak_alias (__strdup, strdup)
56*a1acfa9bSespie #endif
57