]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Remove dependency of xalloc on error, etc.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 9 Aug 2004 18:44:46 +0000 (18:44 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 9 Aug 2004 18:44:46 +0000 (18:44 +0000)
ChangeLog
lib/ChangeLog
lib/Makefile.am
lib/userspec.c
lib/xalloc.h
lib/xmalloc.c

index c63cd6022b24ce400d7b1e3b034f249921e59ae7..ecb31b80bb8e5931bb1670293aafbcd1ae8561de 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2004-08-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * src/csplit.c (xalloc_die): New function.
+       (main): Remove now-obsolete initialization of xalloc_fail_func.
+
        * src/md5sum.c: Adjust to sha->sha1 renaming.
 
 2004-08-07  Paul Eggert  <eggert@cs.ucla.edu>
index 6b1bc02675519da1a2e10b36a37fb05496020024..c7a35cab6ceae3548555614cbf18ce93d5bf427e 100644 (file)
@@ -1,5 +1,14 @@
 2004-08-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * xalloc-die.c: New files.
+       * xalloc.h (xalloc_fail_func, xalloc_msg_memory_exhausted): Remove.
+       All uses removed.
+       * xmalloc.c (xalloc_fail_func, xalloc_msg_memory_exhausted): Likewise.
+       Move inclusions of gettext.h, error.h, exitfail.h to xalloc-die.c.
+       (_, N_, xalloc_die): Move to xalloc-die.c.
+       * userspec.c (parse_user_spaec): Use xstrdup rather than strdup,
+       so that we needn't mess with xalloc_msg_memory_exhausted.
+
        * sha1.h (sha1_ctx): Renamed from sha_ctx.
        (sha1_init_ctx): Renamed from sha_init_ctx.
        (sha1_process_block): Renamed from sha_process_block.
index 14fa776128f8fb0f3f35906846e1e47e07a063a7..ec6f4645bb49f49ce86ac1fe756d9cf8d2e88bbc 100644 (file)
@@ -122,6 +122,7 @@ libfetish_a_SOURCES = \
   utimens.c utimens.h \
   version-etc.c version-etc.h \
   xalloc.h \
+  xalloc-die.c \
   xfts.c xfts.h \
   xgetcwd.c xgetcwd.h \
   xgethostname.c xgethostname.h \
index 820c710279592dd9beb1b3461b46ad42d987be40..6bf40895d92264e852788aeeefb43cc0b3d0eb16 100644 (file)
@@ -277,25 +277,10 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
   if (error_msg == NULL)
     {
       if (u != NULL)
-       {
-         *username_arg = strdup (u);
-         if (*username_arg == NULL)
-           error_msg = xalloc_msg_memory_exhausted;
-       }
+       *username_arg = xstrdup (u);
 
-      if (groupname != NULL && error_msg == NULL)
-       {
-         *groupname_arg = strdup (groupname);
-         if (*groupname_arg == NULL)
-           {
-             if (*username_arg != NULL)
-               {
-                 free (*username_arg);
-                 *username_arg = NULL;
-               }
-             error_msg = xalloc_msg_memory_exhausted;
-           }
-       }
+      if (groupname != NULL)
+       *groupname_arg = xstrdup (groupname);
     }
 
   if (error_msg && dot)
index 5985892c912eb663208a2e80a04a159dc486d72a..d81f2a67648844cfcc5cd616d81ac695ccd82015 100644 (file)
@@ -38,19 +38,9 @@ extern "C" {
 #  define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
 # endif
 
-
-/* If this pointer is non-zero, run the specified function upon each
-   allocation failure.  It is initialized to zero. */
-extern void (*xalloc_fail_func) (void);
-
-/* If XALLOC_FAIL_FUNC is undefined or a function that returns, this
-   message is output.  It is translated via gettext.
-   Its value is "memory exhausted".  */
-extern char const xalloc_msg_memory_exhausted[];
-
-/* This function is always triggered when memory is exhausted.  It is
-   in charge of honoring the two previous items.  It exits with status
-   exit_failure (defined in exitfail.h).  This is the
+/* This function is always triggered when memory is exhausted.
+   It must be defined by the application, either explicitly
+   or by using gnulib's xalloc-die module.  This is the
    function to call when one wants the program to die because of a
    memory allocation failure.  */
 extern void xalloc_die (void) ATTRIBUTE_NORETURN;
index cc7501974d9771a802e5ca3afd3ac0c841bdb499..9b7a948c2f18bc342294088ecbe2d2ab94f84ca6 100644 (file)
@@ -1,6 +1,6 @@
 /* xmalloc.c -- malloc with out of memory checking
 
-   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2003,
+   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
 #include <stdlib.h>
 #include <string.h>
 
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-#include "error.h"
-#include "exitfail.h"
-
 #ifndef SIZE_MAX
 # define SIZE_MAX ((size_t) -1)
 #endif
 
-/* If non NULL, call this function when memory is exhausted. */
-void (*xalloc_fail_func) (void) = 0;
-
-/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
-   before exiting when memory is exhausted.  Goes through gettext. */
-char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
-
-void
-xalloc_die (void)
-{
-  if (xalloc_fail_func)
-    (*xalloc_fail_func) ();
-  error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
-  /* The `noreturn' cannot be given to error, since it may return if
-     its first argument is 0.  To help compilers understand the
-     xalloc_die does terminate, call abort.  */
-  abort ();
-}
-
 /* Allocate an array of N objects, each with S bytes of memory,
    dynamically, with error checking.  S must be nonzero.  */