Back to index

nagios-plugins  1.4.16
strdup.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006, 2007, 2009,
00002    2010 Free Software 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 3, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00019 
00020 #ifndef _LIBC
00021 # include <config.h>
00022 #endif
00023 
00024 /* Get specification.  */
00025 #include <string.h>
00026 
00027 #include <stdlib.h>
00028 
00029 #undef __strdup
00030 #ifdef _LIBC
00031 # undef strdup
00032 #endif
00033 
00034 #ifndef weak_alias
00035 # define __strdup strdup
00036 #endif
00037 
00038 /* Duplicate S, returning an identical malloc'd string.  */
00039 char *
00040 __strdup (const char *s)
00041 {
00042   size_t len = strlen (s) + 1;
00043   void *new = malloc (len);
00044 
00045   if (new == NULL)
00046     return NULL;
00047 
00048   return (char *) memcpy (new, s, len);
00049 }
00050 #ifdef libc_hidden_def
00051 libc_hidden_def (__strdup)
00052 #endif
00053 #ifdef weak_alias
00054 weak_alias (__strdup, strdup)
00055 #endif