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