diff --git a/ChangeLog b/ChangeLog index 0b5398a..fe85941 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,25 @@ +2003-07-02 Paul Eggert + * pch.c (intuit_diff_type): If a unified-diff header line contains trailing CR, strip CR from each body line. This corrects a bug introduced in the 2003-05-18 patch. Bug reported by Andreas Gruenbacher. + * mkdir.c, rmdir.c, m4/rmdir.m4: Remove; we no longer + need to worry about ancient hosts that lack these functions. + + * addext.c, backupfile.c, backupfile.h, dirname.h, m4/backupfile.m4, + m4/onceonly.m4, m4/quote.m4, malloc.c, quote,c, quote.h, realloc.c, + strcasecmp.c, xalloc.h, xmalloc.c: Sync with gnulib. + * stdbool_.h: Renamed from stdbool.h.in; all uses changed. + This renaming is imported from gnulib. + * m4/strcase.m4: New file, imported from gnulib. + + * Makefile.in (LIBSRCS): Remove mkdir.c and rmdir.c. + (stdbool.h): Put output into temporary file and then rename it; + this change is imported from gnulib. + (mostlyclean): Clean stdbool.h-t too. + (ACINCLUDE_INPUTS): Remove rmdir.m4. Add strcase.m4. * configure.ac (gl_FUNC_RMDIR): Remove. (jm_PREREQ_ADDEXT): Remove; now down by gl_BACKUPFILE. (gl_STRCASE, gl_XALLOC): Add. @@ -169,15 +186,15 @@ * configure.ac (AC_PROG_CC_STDC): Add. * util.c (vararg_start): Remove. All uses changed to va_start. Always include . - + * configure.ac (AC_CANONICAL_HOST): Remove. (AC_REPLACE_FUNCS): Add strncasecmp. (AC_CHECK_DECLS): Add mktemp. - + * patch.c (main): Remove useless prototype decl. (mktemp): Don't declare if HAVE_DECL_MKTEMP || defined mktemp. (make_temp): Now accepts char, not int. - + 2002-05-26 Paul Eggert * patch.c (not_defined): Prepend newline. All uses changed. diff --git a/Makefile.in b/Makefile.in index 6c43cc5..eaac915 100644 --- a/Makefile.in +++ b/Makefile.in @@ -61,8 +61,8 @@ CONFIG_STATUS = config.status SHELL = /bin/sh -LIBSRCS = error.c malloc.c memchr.c mkdir.c \ - realloc.c rmdir.c strcasecmp.c strncasecmp.c +LIBSRCS = error.c malloc.c memchr.c \ + realloc.c strcasecmp.c strncasecmp.c SRCS = $(LIBSRCS) \ addext.c argmatch.c backupfile.c \ basename.c dirname.c \ @@ -87,7 +87,7 @@ HDRS = argmatch.h backupfile.h common.h dirname.h \ MISC = AUTHORS COPYING ChangeLog INSTALL Makefile.in NEWS README \ aclocal.m4 \ config.hin configure configure.ac \ - install-sh mkinstalldirs patch.man stdbool.h.in + install-sh mkinstalldirs patch.man stdbool_.h DISTFILES = $(MISC) $(SRCS) $(HDRS) DISTFILES_M4 = $(ACINCLUDE_INPUTS) DISTFILES_PC = pc/chdirsaf.c @@ -133,9 +133,9 @@ configure: configure.ac $(srcdir)/aclocal.m4 cd $(srcdir) && autoconf config.hin: configure.ac $(srcdir)/aclocal.m4 cd $(srcdir) && rm -f config.hin && autoheader -stdbool.h: stdbool.h.in - sed -e 's/@''HAVE__BOOL''@/@HAVE__BOOL@/g' \ - <$(srcdir)/stdbool.h.in >stdbool.h +stdbool.h: stdbool_.h + sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool_.h > stdbool.h-t + mv stdbool.h-t stdbool.h M4DIR = $(srcdir)/m4 ACINCLUDE_INPUTS = \ @@ -154,9 +154,9 @@ ACINCLUDE_INPUTS = \ $(M4DIR)/quote.m4 \ $(M4DIR)/quotearg.m4 \ $(M4DIR)/realloc.m4 \ - $(M4DIR)/rmdir.m4 \ $(M4DIR)/setmode.m4 \ $(M4DIR)/stdbool.m4 \ + $(M4DIR)/strcase.m4 \ $(M4DIR)/unlocked-io.m4 \ $(M4DIR)/utimbuf.m4 \ $(M4DIR)/xalloc.m4 @@ -168,7 +168,7 @@ TAGS: $(HDRS) $(SRCS) etags $(HDRS) $(SRCS) mostlyclean:: - rm -f core* *core *.$(OBJEXT) *_.c stdbool.h + rm -f core* *core *.$(OBJEXT) *_.c stdbool.h stdbool.h-t clean:: mostlyclean rm -f patch$(EXEEXT) @@ -206,7 +206,6 @@ error.$(OBJEXT): error.h gettext.h unlocked-io.h getopt.$(OBJEXT) getopt1.$(OBJEXT): getopt.h inp.$(OBJEXT): backupfile.h $(COMMON) inp.h pch.h quotearg.h util.h xalloc.h maketime.$(OBJEXT): maketime.h partime.h -mkdir.$(OBJEXT): dirname.h xalloc.h partime.$(OBJEXT): partime.h patch.$(OBJEXT): argmatch.h backupfile.h $(COMMON) getopt.h inp.h \ pch.h quotearg.h util.h version.h xalloc.h diff --git a/addext.c b/addext.c index a69c174..fff64f7 100644 --- a/addext.c +++ b/addext.c @@ -31,19 +31,13 @@ # define HAVE_LONG_FILE_NAMES 0 #endif -#if HAVE_LIMITS_H -# include -#endif +#include #ifndef _POSIX_NAME_MAX # define _POSIX_NAME_MAX 14 #endif -#include -#if HAVE_STRING_H -# include -#else -# include -#endif +#include +#include #if HAVE_UNISTD_H # include diff --git a/backupfile.c b/backupfile.c index b0c3976..7ea76b4 100644 --- a/backupfile.c +++ b/backupfile.c @@ -1,6 +1,7 @@ /* backupfile.c -- make Emacs style backup file names - Copyright (C) 1990,91,92,93,94,95,96,97,98,99,2000, 2001, 2002 Free Software - Foundation, Inc. + + Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,13 +25,9 @@ # include #endif +#include #include -#include -#if HAVE_STRING_H -# include -#else -# include -#endif +#include #if HAVE_DIRENT_H # include @@ -56,23 +53,7 @@ # define CLOSEDIR(d) closedir (d) #endif -#if HAVE_STDLIB_H -# include -#endif - -#ifndef HAVE_DECL_GETENV -"this configure-time declaration test was not run" -#endif -#if !HAVE_DECL_GETENV -char *getenv (); -#endif - -#ifndef HAVE_DECL_MALLOC -"this configure-time declaration test was not run" -#endif -#if !HAVE_DECL_MALLOC -char *malloc (); -#endif +#include #if HAVE_DIRENT_H || HAVE_NDIR_H || HAVE_SYS_DIR_H || HAVE_SYS_NDIR_H # define HAVE_DIR 1 @@ -80,12 +61,8 @@ char *malloc (); # define HAVE_DIR 0 #endif -#if HAVE_LIMITS_H -# include -#endif -#ifndef CHAR_BIT -# define CHAR_BIT 8 -#endif +#include + /* Upper bound on the string length of an integer converted to string. 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit; add 1 for integer division truncation; add 1 more for a minus sign. */ @@ -114,8 +91,8 @@ char *malloc (); to numbered) backup file name. */ const char *simple_backup_suffix = "~"; -static int max_backup_version PARAMS ((const char *, const char *)); -static int version_number PARAMS ((const char *, const char *, size_t)); +static int max_backup_version (const char *, const char *); +static int version_number (const char *, const char *, size_t); /* Return the name of the new backup file for file FILE, allocated with malloc. Return 0 if out of memory. diff --git a/backupfile.h b/backupfile.h index b9b973c..fe5e1de 100644 --- a/backupfile.h +++ b/backupfile.h @@ -1,5 +1,7 @@ /* backupfile.h -- declarations for making Emacs style backup file names - Copyright (C) 1990-1992, 1997-1999 Free Software Foundation, Inc. + + Copyright (C) 1990, 1991, 1992, 1997, 1998, 1999, 2003 Free + Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -44,17 +46,9 @@ enum backup_type extern char const *simple_backup_suffix; -# ifndef PARAMS -# if defined PROTOTYPES || (defined __STDC__ && __STDC__) -# define PARAMS(Args) Args -# else -# define PARAMS(Args) () -# endif -# endif - -char *find_backup_file_name PARAMS ((char const *, enum backup_type)); -enum backup_type get_version PARAMS ((char const *context, char const *arg)); -enum backup_type xget_version PARAMS ((char const *context, char const *arg)); -void addext PARAMS ((char *, char const *, int)); +char *find_backup_file_name (char const *, enum backup_type); +enum backup_type get_version (char const *context, char const *arg); +enum backup_type xget_version (char const *context, char const *arg); +void addext (char *, char const *, int); #endif /* ! BACKUPFILE_H_ */ diff --git a/dirname.h b/dirname.h index cea14c0..62da37d 100644 --- a/dirname.h +++ b/dirname.h @@ -1,4 +1,6 @@ -/* Copyright (C) 1998, 2001 Free Software Foundation, Inc. +/* Take file names apart into directory and base names. + + Copyright (C) 1998, 2001, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,13 +19,7 @@ #ifndef DIRNAME_H_ # define DIRNAME_H_ 1 -# ifndef PARAMS -# if defined PROTOTYPES || (defined __STDC__ && __STDC__) -# define PARAMS(Args) Args -# else -# define PARAMS(Args) () -# endif -# endif +# include # ifndef DIRECTORY_SEPARATOR # define DIRECTORY_SEPARATOR '/' @@ -37,11 +33,11 @@ # define FILESYSTEM_PREFIX_LEN(Filename) 0 # endif -char *base_name PARAMS ((char const *path)); -char *dir_name PARAMS ((char const *path)); -size_t base_len PARAMS ((char const *path)); -size_t dir_len PARAMS ((char const *path)); +char *base_name (char const *path); +char *dir_name (char const *path); +size_t base_len (char const *path); +size_t dir_len (char const *path); -int strip_trailing_slashes PARAMS ((char *path)); +int strip_trailing_slashes (char *path); #endif /* not DIRNAME_H_ */ diff --git a/m4/backupfile.m4 b/m4/backupfile.m4 index 0f63f4e..f3c2aa5 100644 --- a/m4/backupfile.m4 +++ b/m4/backupfile.m4 @@ -1,5 +1,5 @@ -# backupfile.m4 serial 1 -dnl Copyright (C) 2002 Free Software Foundation, Inc. +# backupfile.m4 serial 3 +dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -11,13 +11,11 @@ AC_DEFUN([gl_BACKUPFILE], dnl Prerequisites of lib/backupfile.c. AC_REQUIRE([AC_HEADER_DIRENT]) AC_REQUIRE([AC_FUNC_CLOSEDIR_VOID]) - AC_CHECK_HEADERS_ONCE(limits.h stdlib.h string.h) - AC_CHECK_DECLS_ONCE(getenv malloc) jm_CHECK_TYPE_STRUCT_DIRENT_D_INO dnl Prerequisites of lib/addext.c. AC_REQUIRE([jm_AC_DOS]) - AC_SYS_LONG_FILE_NAMES - AC_CHECK_HEADERS_ONCE(limits.h string.h unistd.h) + AC_REQUIRE([AC_SYS_LONG_FILE_NAMES]) + AC_CHECK_HEADERS_ONCE(unistd.h) AC_CHECK_FUNCS(pathconf) ]) diff --git a/m4/onceonly.m4 b/m4/onceonly.m4 index 4ab8fd0..50b33f4 100644 --- a/m4/onceonly.m4 +++ b/m4/onceonly.m4 @@ -1,4 +1,4 @@ -# onceonly.m4 serial 3 +# onceonly.m4 serial 3 (gettext-0.12) dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General diff --git a/m4/quote.m4 b/m4/quote.m4 index 025911f..14ce1b6 100644 --- a/m4/quote.m4 +++ b/m4/quote.m4 @@ -1,5 +1,5 @@ -# quote.m4 serial 1 -dnl Copyright (C) 2002 Free Software Foundation, Inc. +# quote.m4 serial 2 +dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -9,5 +9,5 @@ dnl the same distribution terms as the rest of that program. AC_DEFUN([gl_QUOTE], [ dnl Prerequisites of lib/quote.c. - AC_CHECK_HEADERS_ONCE(stddef.h) + dnl (none) ]) diff --git a/m4/rmdir.m4 b/m4/rmdir.m4 deleted file mode 100644 index a86ff78..0000000 --- a/m4/rmdir.m4 +++ /dev/null @@ -1,22 +0,0 @@ -# rmdir.m4 serial 1 -dnl Copyright (C) 2002 Free Software Foundation, Inc. -dnl This file is free software, distributed under the terms of the GNU -dnl General Public License. As a special exception to the GNU General -dnl Public License, this file may be distributed as part of a program -dnl that contains a configuration script generated by Autoconf, under -dnl the same distribution terms as the rest of that program. - -AC_DEFUN([gl_FUNC_RMDIR], -[ - AC_REPLACE_FUNCS(rmdir) - if test $ac_cv_func_rmdir = no; then - gl_PREREQ_RMDIR - fi -]) - -# Prerequisites of lib/rmdir.c. -AC_DEFUN([gl_PREREQ_RMDIR], [ - AC_REQUIRE([AC_HEADER_STAT]) - : -]) - diff --git a/m4/strcase.m4 b/m4/strcase.m4 new file mode 100644 index 0000000..3fd25d0 --- /dev/null +++ b/m4/strcase.m4 @@ -0,0 +1,39 @@ +# strcase.m4 serial 1 +dnl Copyright (C) 2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +AC_DEFUN([gl_STRCASE], +[ + gl_FUNC_STRCASECMP + gl_FUNC_STRNCASECMP +]) + +AC_DEFUN([gl_FUNC_STRCASECMP], +[ + AC_REPLACE_FUNCS(strcasecmp) + if test $ac_cv_func_strcasecmp = no; then + gl_PREREQ_STRCASECMP + fi +]) + +AC_DEFUN([gl_FUNC_STRNCASECMP], +[ + AC_REPLACE_FUNCS(strncasecmp) + if test $ac_cv_func_strncasecmp = no; then + gl_PREREQ_STRNCASECMP + fi +]) + +# Prerequisites of lib/strcasecmp.c. +AC_DEFUN([gl_PREREQ_STRCASECMP], [ + : +]) + +# Prerequisites of lib/strncasecmp.c. +AC_DEFUN([gl_PREREQ_STRNCASECMP], [ + : +]) diff --git a/malloc.c b/malloc.c index 5e7674b..a43d169 100644 --- a/malloc.c +++ b/malloc.c @@ -22,14 +22,12 @@ #endif #undef malloc -#include - -char *malloc (); +#include /* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */ -char * +void * rpl_malloc (size_t n) { if (n == 0) diff --git a/mkdir.c b/mkdir.c deleted file mode 100644 index 7c756a2..0000000 --- a/mkdir.c +++ /dev/null @@ -1,76 +0,0 @@ -/* On some systems, mkdir ("foo/", 0700) fails because of the trailing - slash. On those systems, this wrapper removes the trailing slash. - Copyright (C) 2001 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* written by Jim Meyering */ - -#include - -/* Disable the definition of mkdir to rpl_mkdir (from config.h) in this - file. Otherwise, we'd get conflicting prototypes for rpl_mkdir on - most systems. */ -#undef mkdir - -#include -#include -#include -#if HAVE_STDLIB_H -# include -#endif - -#if HAVE_STRING_H -# include -#else -# include -#endif - -#include "dirname.h" -#include "xalloc.h" - -#ifndef HAVE_DECL_FREE -"this configure-time declaration test was not run" -#endif -#if !HAVE_DECL_FREE -void free (); -#endif - -/* This function is required at least for NetBSD 1.5.2. */ - -int -rpl_mkdir (char const *dir, mode_t mode) -{ - int ret_val; - char *tmp_dir; - size_t len = strlen (dir); - - if (len && dir[len - 1] == '/') - { - tmp_dir = xstrdup (dir); - strip_trailing_slashes (tmp_dir); - } - else - { - tmp_dir = (char *) dir; - } - - ret_val = mkdir (tmp_dir, mode); - - if (tmp_dir != dir) - free (tmp_dir); - - return ret_val; -} diff --git a/quote.c b/quote.c index 1284937..5f11d83 100644 --- a/quote.c +++ b/quote.c @@ -21,10 +21,6 @@ # include #endif -#if HAVE_STDDEF_H -# include /* For the definition of size_t on windows w/MSVC. */ -#endif -#include #include "quotearg.h" #include "quote.h" diff --git a/quote.h b/quote.h index c750b1e..682f9d1 100644 --- a/quote.h +++ b/quote.h @@ -1,5 +1,7 @@ /* quote.h - prototypes for quote.c - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + + Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,13 +18,5 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef PARAMS -# if defined PROTOTYPES || (defined __STDC__ && __STDC__) -# define PARAMS(Args) Args -# else -# define PARAMS(Args) () -# endif -#endif - -char const *quote_n PARAMS ((int n, char const *name)); -char const *quote PARAMS ((char const *name)); +char const *quote_n (int n, char const *name); +char const *quote (char const *name); diff --git a/realloc.c b/realloc.c index d0d3e4a..ccbf991 100644 --- a/realloc.c +++ b/realloc.c @@ -1,5 +1,5 @@ /* Work around bug on some systems where realloc (NULL, 0) fails. - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,19 +22,14 @@ #endif #undef realloc -#include - -char *malloc (); -char *realloc (); +#include /* Change the size of an allocated block of memory P to N bytes, with error checking. If N is zero, change it to 1. If P is NULL, use malloc. */ -char * -rpl_realloc (p, n) - char *p; - size_t n; +void * +rpl_realloc (void *p, size_t n) { if (n == 0) n = 1; diff --git a/rmdir.c b/rmdir.c deleted file mode 100644 index 2a92803..0000000 --- a/rmdir.c +++ /dev/null @@ -1,87 +0,0 @@ -/* BSD compatible remove directory function for System V - Copyright (C) 1988, 1990 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#if HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include -#ifndef errno -extern int errno; -#endif - -#if STAT_MACROS_BROKEN -# undef S_ISDIR -#endif - -#if !defined(S_ISDIR) && defined(S_IFDIR) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif - -/* rmdir adapted from GNU tar. */ - -/* Remove directory DPATH. - Return 0 if successful, -1 if not. */ - -int -rmdir (dpath) - char *dpath; -{ - pid_t cpid; - int status; - struct stat statbuf; - - if (stat (dpath, &statbuf) != 0) - return -1; /* errno already set */ - - if (!S_ISDIR (statbuf.st_mode)) - { - errno = ENOTDIR; - return -1; - } - - cpid = fork (); - switch (cpid) - { - case -1: /* cannot fork */ - return -1; /* errno already set */ - - case 0: /* child process */ - execl ("/bin/rmdir", "rmdir", dpath, (char *) 0); - _exit (1); - - default: /* parent process */ - - /* Wait for kid to finish. */ - - while (wait (&status) != cpid) - /* Do nothing. */ ; - - if (status) - { - - /* /bin/rmdir failed. */ - - errno = EIO; - return -1; - } - return 0; - } -} diff --git a/stdbool.h.in b/stdbool_.h similarity index 100% rename from stdbool.h.in rename to stdbool_.h diff --git a/strcasecmp.c b/strcasecmp.c index ae7601d..cf4ab88 100644 --- a/strcasecmp.c +++ b/strcasecmp.c @@ -29,7 +29,7 @@ # define LENGTH_LIMIT_EXPR(Expr) 0 #endif -#include +#include #include #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) diff --git a/xalloc.h b/xalloc.h index 098a6c2..c6ca117 100644 --- a/xalloc.h +++ b/xalloc.h @@ -1,5 +1,7 @@ /* xalloc.h -- malloc with out-of-memory checking - Copyright (C) 1990-1998, 1999, 2000 Free Software Foundation, Inc. + + Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,13 +20,7 @@ #ifndef XALLOC_H_ # define XALLOC_H_ -# ifndef PARAMS -# if defined PROTOTYPES || (defined __STDC__ && __STDC__) -# define PARAMS(Args) Args -# else -# define PARAMS(Args) () -# endif -# endif +# include # ifndef __attribute__ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ @@ -36,14 +32,9 @@ # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) # endif -/* Exit value when the requested amount of memory is not available. - It is initialized to EXIT_FAILURE, but the caller may set it to - some other value. */ -extern int xalloc_exit_failure; - /* If this pointer is non-zero, run the specified function upon each allocation failure. It is initialized to zero. */ -extern void (*xalloc_fail_func) PARAMS ((void)); +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. @@ -51,20 +42,20 @@ extern void (*xalloc_fail_func) PARAMS ((void)); extern char const xalloc_msg_memory_exhausted[]; /* This function is always triggered when memory is exhausted. It is - in charge of honoring the three previous items. This is the + in charge of honoring the two previous items. It exits with status + exit_failure (defined in exitfail.h). This is the function to call when one wants the program to die because of a memory allocation failure. */ -extern void xalloc_die PARAMS ((void)) ATTRIBUTE_NORETURN; +extern void xalloc_die (void) ATTRIBUTE_NORETURN; -void *xmalloc PARAMS ((size_t n)); -void *xcalloc PARAMS ((size_t n, size_t s)); -void *xrealloc PARAMS ((void *p, size_t n)); -char *xstrdup PARAMS ((const char *str)); +void *xmalloc (size_t n); +void *xcalloc (size_t n, size_t s); +void *xrealloc (void *p, size_t n); +char *xstrdup (const char *str); -# define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items))) -# define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items))) -# define XREALLOC(Ptr, Type, N_items) \ - ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items))) +# define XMALLOC(Type, N_items) xmalloc (sizeof (Type) * (N_items)) +# define XCALLOC(Type, N_items) xcalloc (sizeof (Type), N_items) +# define XREALLOC(Ptr, Type, N_items) xrealloc (Ptr, sizeof (Type) * (N_items)) /* Declare and alloc memory for VAR of type TYPE. */ # define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1) @@ -78,7 +69,7 @@ char *xstrdup PARAMS ((const char *str)); /* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */ # define CCLONE(Src, Num) \ - (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num))) + (memcpy (xmalloc (sizeof *(Src) * (Num)), Src, sizeof *(Src) * (Num))) /* Return a malloc'ed copy of SRC. */ # define CLONE(Src) CCLONE (Src, 1) diff --git a/xmalloc.c b/xmalloc.c index 3affee7..ead5039 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -1,5 +1,7 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990-1999, 2000, 2002 Free Software Foundation, Inc. + + Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,6 +37,7 @@ void free (); #define N_(msgid) msgid #include "error.h" +#include "exitfail.h" #include "xalloc.h" #ifndef EXIT_FAILURE @@ -51,12 +54,8 @@ void free (); "you must run the autoconf test for a GNU libc compatible realloc" #endif -/* Exit value when the requested amount of memory is not available. - The caller may set it to some other value. */ -int xalloc_exit_failure = EXIT_FAILURE; - /* If non NULL, call this function when memory is exhausted. */ -void (*xalloc_fail_func) PARAMS ((void)) = 0; +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. */ @@ -67,7 +66,7 @@ xalloc_die (void) { if (xalloc_fail_func) (*xalloc_fail_func) (); - error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted)); + 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 exit. */