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