Blame lib/malloc.c

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