strndup.c

00001 /* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2005 Free Software Foundation, Inc.
00002 
00003    NOTE: The canonical source of this file is maintained with the GNU C Library.
00004    Bugs can be reported to bug-glibc@prep.ai.mit.edu.
00005 
00006    This program is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU Lesser General Public License as published by the
00008    Free Software Foundation; either version 2.1, or (at your option) any
00009    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 Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public License
00017    along 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 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023 
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 /* Get strnlen. */
00028 #include "strnlen.h"
00029 
00030 #undef __strndup
00031 #undef strndup
00032 
00033 #ifndef weak_alias
00034 # define __strndup strndup
00035 #endif
00036 
00037 char *
00038 __strndup (const char *s, size_t n)
00039 {
00040   size_t len = strnlen (s, n);
00041   char *new = malloc (len + 1);
00042 
00043   if (new == NULL)
00044     return NULL;
00045 
00046   new[len] = '\0';
00047   return memcpy (new, s, len);
00048 }
00049 #ifdef weak_alias
00050 weak_alias (__strndup, strndup)
00051 #endif

Generated on Wed Jul 12 17:53:19 2006 for WvStreams by  doxygen 1.4.7