aboutsummaryrefslogtreecommitdiff
path: root/libiberty/xmalloc.c
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-11-22 08:32:26 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-11-22 08:32:26 +0000
commitec25516353caa85f02127114006b85c8d3860c54 (patch)
tree2a1d2ae9f91d97732b595daf55f5397c013d1d7b /libiberty/xmalloc.c
parent7534b8df903c3a7ad66e497e2de2d64363220124 (diff)
gcc:
* Makefile.in, config.gcc, configure.in: Expunge remaining traces of facility for running MD files through C preprocessor. libiberty: * aclocal.m4 (LIB_AC_PROG_CC): Moved here from configure.in. (AC_DEFINE_NOAUTOHEADER): New - work around bug in autoheader. * configure.in: Call AC_C_INLINE and AC_C_CONST. Use three argument form of AC_DEFINE in dummy definitions block. Use AC_DEFINE_NOAUTOHEADER for real definitions of things defined in dummy block. Preload cache variables instead of bypassing tests, where possible. * acconfig.h: Removed. * xmalloc.c (xmalloc_failed): New function, does error reporting on failed allocation. (xmalloc, xcalloc, xrealloc): Use it. * libiberty.h: Move #includes to top. Prototype xmalloc_failed. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37650 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/xmalloc.c')
-rw-r--r--libiberty/xmalloc.c94
1 files changed, 31 insertions, 63 deletions
diff --git a/libiberty/xmalloc.c b/libiberty/xmalloc.c
index 08c23f8126e..3ea2d4afc06 100644
--- a/libiberty/xmalloc.c
+++ b/libiberty/xmalloc.c
@@ -64,6 +64,31 @@ xmalloc_set_program_name (s)
#endif /* HAVE_SBRK */
}
+void
+xmalloc_failed (size)
+ size_t size;
+{
+#ifdef HAVE_SBRK
+ 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%sCannot allocate %lu bytes after allocating %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) size, (unsigned long) allocated);
+#else /* HAVE_SBRK */
+ fprintf (stderr,
+ "\n%s%sCannot allocate %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) size);
+#endif /* HAVE_SBRK */
+ xexit (1);
+}
+
PTR
xmalloc (size)
size_t size;
@@ -74,27 +99,8 @@ xmalloc (size)
size = 1;
newmem = malloc (size);
if (!newmem)
- {
-#ifdef HAVE_SBRK
- 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%sCannot allocate %lu bytes after allocating %lu bytes\n",
- name, *name ? ": " : "",
- (unsigned long) size, (unsigned long) allocated);
-#else /* HAVE_SBRK */
- fprintf (stderr,
- "\n%s%sCannot allocate %lu bytes\n",
- name, *name ? ": " : "",
- (unsigned long) size);
-#endif /* HAVE_SBRK */
- xexit (1);
- }
+ xmalloc_failed (size);
+
return (newmem);
}
@@ -109,27 +115,8 @@ xcalloc (nelem, elsize)
newmem = calloc (nelem, elsize);
if (!newmem)
- {
-#ifdef HAVE_SBRK
- 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%sCannot allocate %lu bytes after allocating %lu bytes\n",
- name, *name ? ": " : "",
- (unsigned long) (nelem * elsize), (unsigned long) allocated);
-#else /* HAVE_SBRK */
- fprintf (stderr,
- "\n%s%sCannot allocate %lu bytes\n",
- name, *name ? ": " : "",
- (unsigned long) (nelem * elsize));
-#endif /* HAVE_SBRK */
- xexit (1);
- }
+ xmalloc_failed (nelem * elsize);
+
return (newmem);
}
@@ -147,26 +134,7 @@ xrealloc (oldmem, size)
else
newmem = realloc (oldmem, size);
if (!newmem)
- {
-#ifdef HAVE_SBRK
- 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%sCannot reallocate %lu bytes after allocating %lu bytes\n",
- name, *name ? ": " : "",
- (unsigned long) size, (unsigned long) allocated);
-#else /* HAVE_SBRK */
- fprintf (stderr,
- "\n%s%sCannot reallocate %lu bytes\n",
- name, *name ? ": " : "",
- (unsigned long) size);
-#endif /* HAVE_SBRK */
- xexit (1);
- }
+ xmalloc_failed (size);
+
return (newmem);
}