Back to index

nagios-plugins  1.4.16
strndup.c
Go to the documentation of this file.
00001 /* A replacement function, for systems that lack strndup.
00002 
00003    Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
00004    2010 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU General Public License as published by the
00008    Free Software Foundation; either version 3, 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 General Public License for more details.
00015 
00016    You should have received a copy of the GNU 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 #include <config.h>
00021 
00022 #include <string.h>
00023 
00024 #include <stdlib.h>
00025 
00026 char *
00027 strndup (char const *s, size_t n)
00028 {
00029   size_t len = strnlen (s, n);
00030   char *new = malloc (len + 1);
00031 
00032   if (new == NULL)
00033     return NULL;
00034 
00035   new[len] = '\0';
00036   return memcpy (new, s, len);
00037 }