+2003-09-13 Bruno Haible <bruno@clisp.org>
+
+ * Makefile.am (libgrt_a_SOURCES): Add closeout.h, closeout.c.
+ * Makefile.msvc (OBJECTS): Add closeout.obj.
+ (closeout.obj): New rule.
+ * Makefile.vms (OBJECTS): Add closeout.obj.
+ (closeout.obj): New rule.
+
2003-07-01 Bruno Haible <bruno@clisp.org>
* readlink.c: New file, trivial link to ../../gettext-tools/lib.
libgrt_a_SOURCES = \
../../gettext-tools/lib/basename.h ../../gettext-tools/lib/basename.c \
+ ../../gettext-tools/lib/closeout.h ../../gettext-tools/lib/closeout.c \
../../gettext-tools/lib/error.h ../../gettext-tools/lib/error.c \
../../gettext-tools/lib/exit.h \
../../gettext-tools/lib/getopt.h ../../gettext-tools/lib/getopt.c ../../gettext-tools/lib/getopt1.c \
SHELL = /bin/sh
-OBJECTS = basename.obj error.obj getopt.obj getopt1.obj progname.obj progreloc.obj relocatable.obj xmalloc.obj xstrdup.obj
+OBJECTS = basename.obj closeout.obj error.obj getopt.obj getopt1.obj progname.obj progreloc.obj relocatable.obj xmalloc.obj xstrdup.obj
all : grt.lib
basename.obj : ..\..\gettext-tools\lib\basename.c
$(CC) $(INCLUDES) $(CFLAGS) -c ..\..\gettext-tools\lib\basename.c
+closeout.obj : ..\..\gettext-tools\lib\closeout.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c ..\..\gettext-tools\lib\closeout.c
+
error.obj : ..\..\gettext-tools\lib\error.c
$(CC) $(INCLUDES) $(CFLAGS) -c ..\..\gettext-tools\lib\error.c
#### End of system configuration section. ####
-OBJECTS = basename.obj,error.obj,getopt.obj,getopt1.obj,progname.obj,progreloc.obj,relocatable.obj,xmalloc.obj,xstrdup.obj
+OBJECTS = basename.obj,closeout.obj,error.obj,getopt.obj,getopt1.obj,progname.obj,progreloc.obj,relocatable.obj,xmalloc.obj,xstrdup.obj
all : grt.olb
write sys$output "Nothing else to be done for 'all'."
basename.obj : [-.-.gettext-tools.lib]basename.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) [-.-.gettext-tools.lib]basename.c
+closeout.obj : [-.-.gettext-tools.lib]closeout.c
+ $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) [-.-.gettext-tools.lib]closeout.c
+
error.obj : [-.-.gettext-tools.lib]error.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) [-.-.gettext-tools.lib]error.c
+2003-09-13 Bruno Haible <bruno@clisp.org>
+
+ Fix behaviour of "<program> --help > /dev/full".
+ * gettext.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * ngettext.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+
2003-06-08 Bruno Haible <bruno@clisp.org>
* Makefile.vms (LDADD): Take options from .opt files.
#include <string.h>
#include <locale.h>
+#include "closeout.h"
#include "error.h"
#include "progname.h"
#include "relocatable.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Parse command line options. */
while ((optchar = getopt_long (argc, argv, "+d:eEhnsV", long_options, NULL))
!= EOF)
#include <locale.h>
#include <errno.h>
+#include "closeout.h"
#include "error.h"
#include "progname.h"
#include "relocatable.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Parse command line options. */
while ((optchar = getopt_long (argc, argv, "+d:eEhV", long_options, NULL))
!= EOF)
+2003-09-13 Bruno Haible <bruno@clisp.org>
+
+ * windows/gettextlib.def: Export close_stdout.
+
2003-09-09 Bruno Haible <bruno@clisp.org>
* configure.ac: Don't test for putc_unlocked.
+2003-09-13 Bruno Haible <bruno@clisp.org>
+
+ * closeout.h: New file, from gnulib with modifications.
+ * closeout.c: New file, from gnulib with modifications.
+ * Makefile.am (libgettextlib_la_SOURCES): Add closeout.h, closeout.c.
+ * Makefile.msvc (OBJECTS): Add closeout.obj.
+ (closeout.obj): New rule.
+ * Makefile.vms (OBJECTS): Add closeout.obj.
+ (closeout.obj): New rule.
+
2003-09-12 Paul Eggert <eggert@twinsun.com>
* progreloc.c (get_full_program_name): Define via prototype.
binary-io.h \
c-ctype.h c-ctype.c \
classpath.h classpath.c \
+ closeout.h closeout.c \
copy-file.h copy-file.c \
error.h error.c \
error-progname.h error-progname.c \
basename.obj \
c-ctype.obj \
classpath.obj \
+ closeout.obj \
copy-file.obj \
error.obj \
error-progname.obj \
classpath.obj : classpath.c
$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c classpath.c
+closeout.obj : closeout.c
+ $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c closeout.c
+
copy-file.obj : copy-file.c
$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c copy-file.c
basename.obj, \
c-ctype.obj, \
classpath.obj, \
+ closeout.obj, \
copy-file.obj, \
error.obj, \
error-progname.obj, \
classpath.obj : classpath.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) classpath.c
+closeout.obj : closeout.c
+ $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) closeout.c
+
copy-file.obj : copy-file.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) copy-file.c
--- /dev/null
+/* closeout.c - close standard output
+ Copyright (C) 1998-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
+ 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 <config.h>
+#endif
+
+/* Specification. */
+#include "closeout.h"
+
+#include <stdio.h>
+#include <errno.h>
+
+#if 0
+#include "unlocked-io.h"
+#include "__fpending.h"
+#endif
+#include "error.h"
+#include "exit.h"
+#include "gettext.h"
+
+#define _(msgid) gettext (msgid)
+
+/* Close standard output, exiting with status STATUS on failure.
+ If a program writes *anything* to stdout, that program should `fflush'
+ stdout and make sure that it succeeds before exiting. Otherwise,
+ suppose that you go to the extreme of checking the return status
+ of every function that does an explicit write to stdout. The last
+ printf can succeed in writing to the internal stream buffer, and yet
+ the fclose(stdout) could still fail (due e.g., to a disk full error)
+ when it tries to write out that buffered data. Thus, you would be
+ left with an incomplete output file and the offending program would
+ exit successfully.
+
+ FIXME: note the fflush suggested above is implicit in the fclose
+ we actually do below. Consider doing only the fflush and/or using
+ setvbuf to inhibit buffering.
+
+ Besides, it's wasteful to check the return value from every call
+ that writes to stdout -- just let the internal stream state record
+ the failure. That's what the ferror test is checking below.
+
+ It's important to detect such failures and exit nonzero because many
+ tools (most notably `make' and other build-management systems) depend
+ on being able to detect failure in other tools via their exit status. */
+
+static void
+close_stdout_status (int status)
+{
+ int e = ferror (stdout) ? 0 : -1;
+
+ /* If the stream's error bit is clear, use fflush without fclose.
+ This avoids a useless close(1) system call in the frequent case
+ that no error occurred. */
+ if (e)
+ {
+ if (fflush (stdout) != 0)
+ e = errno;
+ else
+ return;
+ }
+
+ if (fclose (stdout) != 0)
+ e = errno;
+
+ if (0 <= e)
+ error (status, e, "%s", _("write error"));
+}
+
+/* Close standard output, exiting with status EXIT_FAILURE on failure. */
+void
+close_stdout (void)
+{
+ close_stdout_status (EXIT_FAILURE);
+}
+
+/* Note: When exit (...) calls the atexit-registered
+ close_stdout (), which calls
+ error (status, ...), which calls
+ exit (status),
+ we have undefined behaviour according to ISO C 99 section 7.20.4.3.(2).
+ But in practice there is no problem: The second exit call is executed
+ at a moment when the atexit handlers are no longer active. */
--- /dev/null
+/* close standard output
+ Copyright (C) 1998-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
+ 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. */
+
+#ifndef CLOSEOUT_H
+#define CLOSEOUT_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void close_stdout (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+2003-09-13 Bruno Haible <bruno@clisp.org>
+
+ Fix behaviour of "<program> --help > /dev/full".
+ * hostname.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgattrib.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgcat.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgcmp.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgcomm.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgconv.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgen.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgexec.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgfilter.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgfmt.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msggrep.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msginit.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgmerge.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msgunfmt.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * msguniq.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * urlget.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * xgettext.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * write-po.c (msgdomain_list_print): Don't fclose (stdout) here.
+
2003-09-11 Bruno Haible <bruno@clisp.org>
* po-lex.c (mbfile_getc): Handle unexpected return value of
/* Include this after <sys/socket.h>, to avoid a syntax error on BeOS. */
#include <stdbool.h>
+#include "closeout.h"
#include "error.h"
#include "error-progname.h"
#include "progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
#include <stdlib.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
#include <stdlib.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "str-list.h"
#include "file-list.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
#include <stdlib.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
do_help = false;
do_version = false;
while ((optchar = getopt_long (argc, argv, "D:hmPV", long_options, NULL))
#include <stdio.h>
#include <stdlib.h>
+#include "closeout.h"
#include "dir-list.h"
#include "str-list.h"
#include "file-list.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
more_than = -1;
less_than = -1;
#include <stdlib.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
#include <stdlib.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
# include <unistd.h>
#endif
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "xerror.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
# include <sys/select.h>
#endif
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
#include <string.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
while ((opt = getopt_long (argc, argv, "a:cCd:D:fhjl:o:Pr:vV", long_options,
NULL))
!= EOF)
#include <fnmatch.h>
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
# define HAVE_DIR 0
#endif
+#include "closeout.h"
#include "error.h"
#include "error-progname.h"
#include "progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
#include <string.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "error.h"
#include "error-progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
#include <stdlib.h>
#include <locale.h>
+#include "closeout.h"
#include "error.h"
#include "error-progname.h"
#include "progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
while ((optchar = getopt_long (argc, argv, "d:eEhijl:o:pr:svVw:",
long_options, NULL))
!= EOF)
#include <stdlib.h>
#include <locale.h>
+#include "closeout.h"
#include "dir-list.h"
#include "str-list.h"
#include "error.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
# include <unistd.h>
#endif
+#include "closeout.h"
#include "error.h"
#include "error-progname.h"
#include "progname.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set default values for variables. */
do_help = false;
do_version = false;
if (fflush (fp) || ferror (fp))
error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"),
filename);
- fclose (fp);
+
+ if (fp != stdout)
+ fclose (fp);
}
#include <limits.h>
#include "xgettext.h"
+#include "closeout.h"
#include "dir-list.h"
#include "file-list.h"
#include "str-list.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Set initial value of variables. */
default_domain = MESSAGE_DOMAIN_DEFAULT;
xgettext_global_source_encoding = po_charset_ascii;
+2003-09-13 Bruno Haible <bruno@clisp.org>
+
+ Fix behaviour of "<program> --help > /dev/full".
+ * tstgettext.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+ * tstngettext.c: Include closeout.h.
+ (main): Register close_stdout for execution at program exit.
+
2003-09-11 Bruno Haible <bruno@clisp.org>
* msgfmt-14: New file.
#include <string.h>
#include <locale.h>
+#include "closeout.h"
#include "error.h"
#include "progname.h"
#include "relocatable.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Parse command line options. */
while ((optchar = getopt_long (argc, argv, "+d:eEhnsV", long_options, NULL))
!= EOF)
#include <locale.h>
#include <errno.h>
+#include "closeout.h"
#include "error.h"
#include "progname.h"
#include "relocatable.h"
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
+ /* Ensure that write errors on stdout are detected. */
+ atexit (close_stdout);
+
/* Parse command line options. */
while ((optchar = getopt_long (argc, argv, "+d:hV", long_options, NULL))
!= EOF)
c_isxdigit
c_tolower
c_toupper
+close_stdout
compile_java_class
concatenated_pathname
copy_file_preserving