aboutsummaryrefslogtreecommitdiff
path: root/libiberty/xmalloc.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>1998-11-13 16:36:04 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>1998-11-13 16:36:04 +0000
commita9acf74156d05a933295cba9b800c2c6759296f5 (patch)
tree3ba8d1fed8bcc7504da2c11d5b6e63f2bdf140e3 /libiberty/xmalloc.c
parent67d0f6ab5e3c6fba25e59702f09f44694a0c968b (diff)
downloadgcc-a9acf74156d05a933295cba9b800c2c6759296f5.zip
gcc-a9acf74156d05a933295cba9b800c2c6759296f5.tar.gz
gcc-a9acf74156d05a933295cba9b800c2c6759296f5.tar.bz2
configure.in: Check for calloc.
* configure.in: Check for calloc. * calloc.c: New file. * xmalloc.c (xcalloc): New function. From-SVN: r23642
Diffstat (limited to 'libiberty/xmalloc.c')
-rw-r--r--libiberty/xmalloc.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libiberty/xmalloc.c b/libiberty/xmalloc.c
index b88105a..4f39014 100644
--- a/libiberty/xmalloc.c
+++ b/libiberty/xmalloc.c
@@ -36,6 +36,7 @@ Boston, MA 02111-1307, USA. */
/* 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));
#endif
@@ -95,6 +96,41 @@ xmalloc (size)
}
PTR
+xcalloc (nelem, elsize)
+ size_t nelem, elsize;
+{
+ PTR newmem;
+
+ if (nelem == 0 || elsize == 0)
+ nelem = elsize = 1;
+
+ newmem = calloc (nelem, elsize);
+ if (!newmem)
+ {
+#if ! defined (_WIN32) || defined (__CYGWIN32__)
+ extern char **environ;
+ size_t allocated;
+
+ if (first_break != NULL)
+ allocated = (char *) sbrk (0) - first_break;
+ else
+ allocated = (char *) sbrk (0) - (char *) &environ;
+ fprintf (stderr,
+ "\n%s%sCan not allocate %lu bytes after allocating %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) (nelem * elsize), (unsigned long) allocated);
+#else
+ fprintf (stderr,
+ "\n%s%sCan not allocate %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) (nelem * elsize));
+#endif /* ! _WIN32 || __CYGWIN32 __ */
+ xexit (1);
+ }
+ return (newmem);
+}
+
+PTR
xrealloc (oldmem, size)
PTR oldmem;
size_t size;