Blame gl/malloc.c

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