Blame lib/malloc.c

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