Blame gnulib/lib/malloc.c

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