Blame gnulib/lib/malloc.c

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