pkg-monitoring-plugins/gl/malloc.c

58 lines
1.4 KiB
C
Raw Normal View History

2013-11-26 22:53:19 +00:00
/* malloc() function that is glibc compatible.
2013-11-26 22:53:44 +00:00
2013-11-26 22:55:28 +00:00
Copyright (C) 1997, 1998, 2006, 2007 Free Software Foundation, Inc.
2013-11-26 22:53:19 +00:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
2013-11-26 22:55:28 +00:00
the Free Software Foundation; either version 3, or (at your option)
2013-11-26 22:53:19 +00:00
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
2013-11-26 22:55:28 +00:00
/* written by Jim Meyering and Bruno Haible */
2013-11-26 22:53:19 +00:00
2013-11-26 22:53:44 +00:00
#include <config.h>
2013-11-26 22:55:28 +00:00
/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
#ifdef malloc
# define NEED_MALLOC_GNU
# undef malloc
#endif
2013-11-26 22:53:19 +00:00
2013-11-26 22:55:28 +00:00
/* Specification. */
2013-11-26 22:53:19 +00:00
#include <stdlib.h>
2013-11-26 22:55:28 +00:00
#include <errno.h>
/* Call the system's malloc below. */
#undef malloc
2013-11-26 22:53:19 +00:00
/* Allocate an N-byte block of memory from the heap.
If N is zero, allocate a 1-byte block. */
void *
rpl_malloc (size_t n)
{
2013-11-26 22:55:28 +00:00
void *result;
#ifdef NEED_MALLOC_GNU
2013-11-26 22:53:19 +00:00
if (n == 0)
n = 1;
2013-11-26 22:55:28 +00:00
#endif
result = malloc (n);
#if !HAVE_MALLOC_POSIX
if (result == NULL)
errno = ENOMEM;
#endif
return result;
2013-11-26 22:53:19 +00:00
}