Back to index

nagios-plugins  1.4.16
malloc.c
Go to the documentation of this file.
00001 /* malloc() function that is glibc compatible.
00002 
00003    Copyright (C) 1997-1998, 2006-2007, 2009-2010 Free Software Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00018 
00019 /* written by Jim Meyering and Bruno Haible */
00020 
00021 #include <config.h>
00022 /* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h.  */
00023 #ifdef malloc
00024 # define NEED_MALLOC_GNU
00025 # undef malloc
00026 #endif
00027 
00028 /* Specification.  */
00029 #include <stdlib.h>
00030 
00031 #include <errno.h>
00032 
00033 /* Call the system's malloc below.  */
00034 #undef malloc
00035 
00036 /* Allocate an N-byte block of memory from the heap.
00037    If N is zero, allocate a 1-byte block.  */
00038 
00039 void *
00040 rpl_malloc (size_t n)
00041 {
00042   void *result;
00043 
00044 #ifdef NEED_MALLOC_GNU
00045   if (n == 0)
00046     n = 1;
00047 #endif
00048 
00049   result = malloc (n);
00050 
00051 #if !HAVE_MALLOC_POSIX
00052   if (result == NULL)
00053     errno = ENOMEM;
00054 #endif
00055 
00056   return result;
00057 }