]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Include xalloc.h.
authorJim Meyering <jim@meyering.net>
Sat, 25 Oct 1997 04:43:10 +0000 (04:43 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 25 Oct 1997 04:43:10 +0000 (04:43 +0000)
(xmalloc): Remove function.
(xrealloc): Remove function.
(main): Set xalloc_fail_func to cleanup.
Set xmalloc_exit_failure SORT_FAILURE.

src/sort.c

index 1312c1954c55b7de2f539a1ebbd8e7a9a504bccd..b68b136ce6fa924f4dfd42fc619afa7ec876f1ae 100644 (file)
@@ -37,6 +37,7 @@
 #include "long-options.h"
 #include "error.h"
 #include "xstrtod.h"
+#include "xalloc.h"
 
 #ifdef ENABLE_NLS
 # include <langinfo.h>
@@ -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);