From 0927513b1648b948224eebc4f1d90eda5ba9949e Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 25 Oct 1997 04:43:10 +0000 Subject: Include xalloc.h. (xmalloc): Remove function. (xrealloc): Remove function. (main): Set xalloc_fail_func to cleanup. Set xmalloc_exit_failure SORT_FAILURE. --- src/sort.c | 47 +++++------------------------------------------ 1 file changed, 5 insertions(+), 42 deletions(-) (limited to 'src/sort.c') diff --git a/src/sort.c b/src/sort.c index 1312c1954..b68b136ce 100644 --- a/src/sort.c +++ b/src/sort.c @@ -37,6 +37,7 @@ #include "long-options.h" #include "error.h" #include "xstrtod.h" +#include "xalloc.h" #ifdef ENABLE_NLS # include @@ -347,48 +348,6 @@ cleanup (void) unlink (node->name); } -/* Allocate N bytes of memory dynamically, with error checking. */ - -static char * -xmalloc (unsigned int n) -{ - char *p; - - p = malloc (n); - if (p == 0) - { - error (0, 0, _("virtual memory exhausted")); - cleanup (); - exit (SORT_FAILURE); - } - return p; -} - -/* Change the size of an allocated block of memory P to N bytes, - with error checking. - If P is NULL, run xmalloc. - If N is 0, run free and return NULL. */ - -static char * -xrealloc (char *p, unsigned int n) -{ - if (p == 0) - return xmalloc (n); - if (n == 0) - { - free (p); - return 0; - } - p = realloc (p, n); - if (p == 0) - { - error (0, 0, _("virtual memory exhausted")); - cleanup (); - exit (SORT_FAILURE); - } - return p; -} - static FILE * xtmpfopen (const char *file) { @@ -2554,6 +2513,10 @@ main (int argc, char **argv) if (temp_file_prefix == NULL) temp_file_prefix = DEFAULT_TMPDIR; + /* Change the way xmalloc and xrealloc fail. */ + xmalloc_exit_failure = SORT_FAILURE; + xalloc_fail_func = cleanup; + #ifdef SA_INTERRUPT newact.sa_handler = sighandler; sigemptyset (&newact.sa_mask); -- cgit v1.2.3-54-g00ecf