Blame src/gl/malloc.c

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