Blame gl/malloc.c

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