Blame lib/malloc.c

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