Blame gnulib/malloc.c

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