1 |
/* Duplicate a string |
/* Copyright (C) 1991, 1996, 1997, 1998, 2002 Free Software Foundation, Inc. |
2 |
|
This file is part of the GNU C Library. |
3 |
|
|
4 |
Copyright (C) 1996, 2000 Free Software Foundation, Inc. |
This program is free software; you can redistribute it and/or modify |
5 |
|
it under the terms of the GNU General Public License as published by |
6 |
Written by Miles Bader <miles@gnu.ai.mit.edu> |
the Free Software Foundation; either version 2, or (at your option) |
7 |
|
any later version. |
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License as |
This program is distributed in the hope that it will be useful, |
10 |
published by the Free Software Foundation; either version 2, or (at |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
your option) any later version. |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
|
GNU General Public License for more details. |
13 |
This program is distributed in the hope that it will be useful, but |
|
14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
You should have received a copy of the GNU General Public License along |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
with this program; if not, write to the Free Software Foundation, |
16 |
General Public License for more details. |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
|
|
|
|
You should have received a copy of the GNU General Public License |
|
|
along with this program; if not, write to the Free Software |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
|
17 |
|
|
18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
19 |
#include <config.h> |
#include <config.h> |
20 |
#endif |
#endif |
21 |
|
|
22 |
#ifdef HAVE_STDLIB_H |
#if defined _LIBC || defined STDC_HEADERS |
23 |
#include <stdlib.h> |
# include <stdlib.h> |
24 |
#endif |
# include <string.h> |
25 |
#ifdef HAVE_MALLOC_H |
#else |
26 |
#include <malloc.h> |
char *malloc (); |
27 |
|
char *memcpy (); |
28 |
#endif |
#endif |
29 |
#ifdef HAVE_STRING_H |
|
30 |
#include <string.h> |
#undef __strdup |
31 |
|
#undef strdup |
32 |
|
|
33 |
|
#ifndef weak_alias |
34 |
|
# define __strdup strdup |
35 |
#endif |
#endif |
36 |
|
|
37 |
|
/* Duplicate S, returning an identical malloc'd string. */ |
38 |
char * |
char * |
39 |
strdup (const char *str) |
__strdup (const char *s) |
40 |
{ |
{ |
41 |
if (str) |
size_t len = strlen (s) + 1; |
42 |
{ |
void *new = malloc (len); |
43 |
char *dup = malloc (strlen (str) + 1); |
|
44 |
if (dup) |
if (new == NULL) |
45 |
strcpy (dup, str); |
return NULL; |
46 |
return dup; |
|
47 |
} |
return (char *) memcpy (new, s, len); |
|
else |
|
|
return 0; |
|
48 |
} |
} |
49 |
|
#ifdef libc_hidden_def |
50 |
|
libc_hidden_def (__strdup) |
51 |
|
#endif |
52 |
|
#ifdef weak_alias |
53 |
|
weak_alias (__strdup, strdup) |
54 |
|
#endif |