Blame lib/malloc.c

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