summaryrefslogtreecommitdiff
path: root/libiberty/xmalloc.c
diff options
context:
space:
mode:
authorghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>1998-11-13 16:36:04 +0000
committerghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>1998-11-13 16:36:04 +0000
commit34fa88316071e4f2d3aab04444bbaa996495499c (patch)
tree3ba8d1fed8bcc7504da2c11d5b6e63f2bdf140e3 /libiberty/xmalloc.c
parent28e7433da246f2a1bcf2f555bac47fb7106662de (diff)
downloadgcc-34fa88316071e4f2d3aab04444bbaa996495499c.tar.gz
* configure.in: Check for calloc.
* calloc.c: New file. * xmalloc.c (xcalloc): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@23642 138bc75d-0d04-0410-961f-82ee72b054a4
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 b88105a9b74..4f39014622e 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;