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