/* memory allocation routines with error checking.
- Copyright 1989, 90, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1989-2022 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+Boston, MA 02110-1301, USA. */
/*
#endif
#include "ansidecl.h"
#include "libiberty.h"
+#include "environ.h"
#include <stdio.h>
-#ifdef ANSI_PROTOTYPES
#include <stddef.h>
-#else
-#define size_t unsigned long
-#define ptrdiff_t long
-#endif
#if VMS
#include <stdlib.h>
#include <unixlib.h>
#else
/* For systems with larger pointers than ints, these must be declared. */
-PTR malloc PARAMS ((size_t));
-PTR realloc PARAMS ((PTR, size_t));
-PTR calloc PARAMS ((size_t, size_t));
-PTR sbrk PARAMS ((ptrdiff_t));
+# if HAVE_STDLIB_H && HAVE_UNISTD_H && HAVE_DECL_MALLOC \
+ && HAVE_DECL_REALLOC && HAVE_DECL_CALLOC && HAVE_DECL_SBRK
+# include <stdlib.h>
+# include <unistd.h>
+# else
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+void *malloc (size_t);
+void *realloc (void *, size_t);
+void *calloc (size_t, size_t);
+#ifdef HAVE_SBRK
+void *sbrk (ptrdiff_t);
#endif
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+# endif /* HAVE_STDLIB_H ... */
+#endif /* VMS */
/* The program name if set. */
static const char *name = "";
#endif /* HAVE_SBRK */
void
-xmalloc_set_program_name (s)
- const char *s;
+xmalloc_set_program_name (const char *s)
{
name = s;
#ifdef HAVE_SBRK
}
void
-xmalloc_failed (size)
- size_t size;
+xmalloc_failed (size_t size)
{
#ifdef HAVE_SBRK
- extern char **environ;
size_t allocated;
if (first_break != NULL)
xexit (1);
}
-PTR
-xmalloc (size)
- size_t size;
+void *
+xmalloc (size_t size)
{
- PTR newmem;
+ void *newmem;
if (size == 0)
size = 1;
return (newmem);
}
-PTR
-xcalloc (nelem, elsize)
- size_t nelem, elsize;
+void *
+xcalloc (size_t nelem, size_t elsize)
{
- PTR newmem;
+ void *newmem;
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
return (newmem);
}
-PTR
-xrealloc (oldmem, size)
- PTR oldmem;
- size_t size;
+void *
+xrealloc (void *oldmem, size_t size)
{
- PTR newmem;
+ void *newmem;
if (size == 0)
size = 1;