From: Jim Meyering Date: Sat, 25 Oct 1997 04:43:10 +0000 (+0000) Subject: Include xalloc.h. X-Git-Tag: TEXTUTILS-1_22c~180 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0927513b1648b948224eebc4f1d90eda5ba9949e;p=thirdparty%2Fcoreutils.git Include xalloc.h. (xmalloc): Remove function. (xrealloc): Remove function. (main): Set xalloc_fail_func to cleanup. Set xmalloc_exit_failure SORT_FAILURE. --- diff --git a/src/sort.c b/src/sort.c index 1312c1954c..b68b136ce6 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);