8ebc71fbba6ea78fca2680248a9fac569c73dd33
[debian/tar] / gnu / strdup.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Copyright (C) 1991, 1996-1998, 2002-2004, 2006-2007, 2009-2013 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 3, 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, see <http://www.gnu.org/licenses/>.  */
20
21 #ifndef _LIBC
22 # include <config.h>
23 #endif
24
25 /* Get specification.  */
26 #include <string.h>
27
28 #include <stdlib.h>
29
30 #undef __strdup
31 #ifdef _LIBC
32 # undef strdup
33 #endif
34
35 #ifndef weak_alias
36 # define __strdup strdup
37 #endif
38
39 /* Duplicate S, returning an identical malloc'd string.  */
40 char *
41 __strdup (const char *s)
42 {
43   size_t len = strlen (s) + 1;
44   void *new = malloc (len);
45
46   if (new == NULL)
47     return NULL;
48
49   return (char *) memcpy (new, s, len);
50 }
51 #ifdef libc_hidden_def
52 libc_hidden_def (__strdup)
53 #endif
54 #ifdef weak_alias
55 weak_alias (__strdup, strdup)
56 #endif