diff options
author | Jari Aalto <jari.aalto@cante.net> | 1996-12-23 17:02:34 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:49 +0000 |
commit | ccc6cda312fea9f0468ee65b8f368e9653e1380b (patch) | |
tree | b059878adcfd876c4acb8030deda1eeb918c7e75 /lib/malloc/xmalloc.c | |
parent | 726f63884db0132f01745f1fb4465e6621088ccf (diff) | |
download | android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.tar.gz android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.tar.bz2 android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.zip |
Imported from ../bash-2.0.tar.gz.
Diffstat (limited to 'lib/malloc/xmalloc.c')
-rw-r--r-- | lib/malloc/xmalloc.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/malloc/xmalloc.c b/lib/malloc/xmalloc.c index 4f6dc76..4160651 100644 --- a/lib/malloc/xmalloc.c +++ b/lib/malloc/xmalloc.c @@ -19,8 +19,10 @@ along with Readline; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -#if defined (ALREADY_HAVE_XMALLOC) -#else +#if defined (HAVE_CONFIG_H) +#include <config.h> +#endif + #include <stdio.h> #if defined (HAVE_STDLIB_H) @@ -44,9 +46,10 @@ char * xmalloc (bytes) int bytes; { - char *temp = (char *)malloc (bytes); + char *temp; - if (!temp) + temp = (char *)malloc (bytes); + if (temp == 0) memory_error_and_abort ("xmalloc"); return (temp); } @@ -58,12 +61,9 @@ xrealloc (pointer, bytes) { char *temp; - if (!pointer) - temp = (char *)malloc (bytes); - else - temp = (char *)realloc (pointer, bytes); + temp = pointer ? (char *)realloc (pointer, bytes) : (char *)malloc (bytes); - if (!temp) + if (temp == 0) memory_error_and_abort ("xrealloc"); return (temp); } @@ -72,7 +72,16 @@ static void memory_error_and_abort (fname) char *fname; { - fprintf (stderr, "%s: Out of virtual memory!\n", fname); - abort (); + fprintf (stderr, "%s: out of virtual memory\n", fname); + exit (2); +} + +/* Use this as the function to call when adding unwind protects so we + don't need to know what free() returns. */ +void +xfree (string) + char *string; +{ + if (string) + free (string); } -#endif /* !ALREADY_HAVE_XMALLOC */ |