Back to index

tetex-bin  3.0
strdup.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004 Free Software
00002    Foundation, Inc.
00003 
00004    This file is part of the GNU C Library.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License along
00017    with this program; if not, write to the Free Software Foundation,
00018    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023 
00024 #ifndef _LIBC
00025 /* Get specification.  */
00026 # include "strdup.h"
00027 #endif
00028 
00029 #include <stdlib.h>
00030 #include <string.h>
00031 
00032 #undef __strdup
00033 #undef strdup
00034 
00035 #ifndef weak_alias
00036 # define __strdup strdup
00037 #endif
00038 
00039 /* Duplicate S, returning an identical malloc'd string.  */
00040 char *
00041 __strdup (const char *s)
00042 {
00043   size_t len = strlen (s) + 1;
00044   void *new = malloc (len);
00045 
00046   if (new == NULL)
00047     return NULL;
00048 
00049   return (char *) memcpy (new, s, len);
00050 }
00051 #ifdef libc_hidden_def
00052 libc_hidden_def (__strdup)
00053 #endif
00054 #ifdef weak_alias
00055 weak_alias (__strdup, strdup)
00056 #endif