]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Check for write error on stdout when the program exits.
authorBruno Haible <bruno@clisp.org>
Mon, 15 Sep 2003 19:06:16 +0000 (19:06 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:59 +0000 (12:10 +0200)
37 files changed:
gettext-runtime/lib/ChangeLog
gettext-runtime/lib/Makefile.am
gettext-runtime/lib/Makefile.msvc
gettext-runtime/lib/Makefile.vms
gettext-runtime/src/ChangeLog
gettext-runtime/src/gettext.c
gettext-runtime/src/ngettext.c
gettext-tools/ChangeLog
gettext-tools/lib/ChangeLog
gettext-tools/lib/Makefile.am
gettext-tools/lib/Makefile.msvc
gettext-tools/lib/Makefile.vms
gettext-tools/lib/closeout.c [new file with mode: 0644]
gettext-tools/lib/closeout.h [new file with mode: 0644]
gettext-tools/src/ChangeLog
gettext-tools/src/hostname.c
gettext-tools/src/msgattrib.c
gettext-tools/src/msgcat.c
gettext-tools/src/msgcmp.c
gettext-tools/src/msgcomm.c
gettext-tools/src/msgconv.c
gettext-tools/src/msgen.c
gettext-tools/src/msgexec.c
gettext-tools/src/msgfilter.c
gettext-tools/src/msgfmt.c
gettext-tools/src/msggrep.c
gettext-tools/src/msginit.c
gettext-tools/src/msgmerge.c
gettext-tools/src/msgunfmt.c
gettext-tools/src/msguniq.c
gettext-tools/src/urlget.c
gettext-tools/src/write-po.c
gettext-tools/src/xgettext.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/tstgettext.c
gettext-tools/tests/tstngettext.c
gettext-tools/windows/gettextlib.def

index ef75ef956160a07a93321c5f9c016ffb518d61c5..2432f58ab6bc3c98b728d7d4216f087c2016ebed 100644 (file)
@@ -1,3 +1,11 @@
+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.
index 0a584e2991e82174f79a6a749a8a0f49aaede12e..8078a3567513a23cd948d36e8959b0d222472c7a 100644 (file)
@@ -27,6 +27,7 @@ noinst_LIBRARIES = libgrt.a
 
 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 \
index 421e41f4d15a45a7954ddadad19f386df3eeb48b..01dcb3b3f1a10724bbfec8874799764e7fda7e6a 100644 (file)
@@ -52,13 +52,16 @@ RM = -del
 
 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
 
index 26b3ec8e0b8608a75d70f281f0976dde0f1207da..af9d560db621990867b4d0cbc99469d67e0e71bc 100644 (file)
@@ -27,7 +27,7 @@ RM = delete
 
 #### 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'."
@@ -35,6 +35,9 @@ all : grt.olb
 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
 
index 0ebba3aea5f81bfcb9ca35703694276166932f53..aa834ed0588070a3bf60d1badd452f960c85dfcb 100644 (file)
@@ -1,3 +1,11 @@
+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.
index b39daa508bd1384920aaa11ab6042dba9e150edc..7a6fa516d1d67709de105b1740e8f74570b687a5 100644 (file)
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "error.h"
 #include "progname.h"
 #include "relocatable.h"
@@ -89,6 +90,9 @@ main (int argc, char *argv[])
   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)
index 654a34740b11a8ff956035461230323185215678..8e6b03f77f38ac2e53284d475f25cda908a23f58 100644 (file)
@@ -26,6 +26,7 @@
 #include <locale.h>
 #include <errno.h>
 
+#include "closeout.h"
 #include "error.h"
 #include "progname.h"
 #include "relocatable.h"
@@ -86,6 +87,9 @@ main (int argc, char *argv[])
   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)
index 4069befdde265a1f9236fd66e71899aa619f2bf2..c1aac57bdb90c87f52c6324241a1f2b3fff30957 100644 (file)
@@ -1,3 +1,7 @@
+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.
index 88f575dfffcf51850a5e0d04e3de233d69d2f480..5948692368907cbb8990d3ca5741d77cd2ec904a 100644 (file)
@@ -1,3 +1,13 @@
+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.
index de81701fe25f16f06f6c5e58501e74373c2320bb..3e437bb00214a5a88e7d1bf71333bf2fa04ab988 100644 (file)
@@ -37,6 +37,7 @@ libgettextlib_la_SOURCES = \
   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 \
index fc363b31051ec5b1796c244bad9ab4d3932c98bc..f90705cf19c0739c174345b0ab8cfd318eeb5e8e 100644 (file)
@@ -85,6 +85,7 @@ OBJECTS = \
   basename.obj \
   c-ctype.obj \
   classpath.obj \
+  closeout.obj \
   copy-file.obj \
   error.obj \
   error-progname.obj \
@@ -146,6 +147,9 @@ c-ctype.obj : c-ctype.c
 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
 
index 8415eedf2171a88fb8357421986728a8634ca98f..bd70f258a4fd39ec5044498f34f7b6c408875675 100644 (file)
@@ -43,6 +43,7 @@ OBJECTS = \
   basename.obj, \
   c-ctype.obj, \
   classpath.obj, \
+  closeout.obj, \
   copy-file.obj, \
   error.obj, \
   error-progname.obj, \
@@ -107,6 +108,9 @@ c-ctype.obj : c-ctype.c
 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
 
diff --git a/gettext-tools/lib/closeout.c b/gettext-tools/lib/closeout.c
new file mode 100644 (file)
index 0000000..ab15966
--- /dev/null
@@ -0,0 +1,97 @@
+/* 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.  */
diff --git a/gettext-tools/lib/closeout.h b/gettext-tools/lib/closeout.h
new file mode 100644 (file)
index 0000000..7f1e478
--- /dev/null
@@ -0,0 +1,31 @@
+/* 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
index 190e7ed39c0a099979cce5efea2a7da5c97b870d..4028f77a48245daaf7c296ebb59eb8abbc7d0768 100644 (file)
@@ -1,3 +1,42 @@
+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
index 7099d9fcaacffa179a8d38bf139cf89170464578..67e60726de64c029e054c83d56ca9b13590e60ba 100644 (file)
@@ -77,6 +77,7 @@
 /* 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"
@@ -133,6 +134,9 @@ main (int argc, char *argv[])
   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;
index 2856323b90aa46e9046d7e80350dad237bb6f46f..7e3368931549f0554d97461d4501e7e96613eb3e 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -145,6 +146,9 @@ main (int argc, char **argv)
   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;
index 592c820f90809add4085bb6419493fd87fee39c1..1211aa213a1dbe7ee0d3db4ca844bb20eee71556 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "str-list.h"
 #include "file-list.h"
@@ -117,6 +118,9 @@ main (int argc, char **argv)
   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;
index 3f211b6fb5683eeb3add36d94a3bb6667aa87d22..0ec8309969a6a4eb2df34a5ff4df52b8cb98ea51 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -89,6 +90,9 @@ main (int argc, char *argv[])
   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))
index 206ba1cd4ef7ae0fc12d777f4ca150705bbb3c4d..5f18297de40bf1ab0b02ce6cf65f370062d2feb8 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "str-list.h"
 #include "file-list.h"
@@ -119,6 +120,9 @@ main (int argc, char *argv[])
   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;
index 7ff480a471898f9d37c29a056ee15396aeb87ada..448bbffa6706c05087619dfd8dcfa722b9153212 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -109,6 +110,9 @@ main (int argc, char **argv)
   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;
index fdb06ca81a9497b7083751e2ea681260b4afcb66..f90a37c47210b8e6624dd5d1e516c137e0848f6f 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -102,6 +103,9 @@ main (int argc, char **argv)
   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;
index 42188ffacff6677f973cc3912fea46abb6ec1863..01f1066afed57e01f9705110219c17e09d6396db 100644 (file)
@@ -33,6 +33,7 @@
 # include <unistd.h>
 #endif
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "xerror.h"
@@ -115,6 +116,9 @@ main (int argc, char **argv)
   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;
index 0cc85b1a474e2b067caa53b4f840c632b00d876d..3f2749cee122e2e1c531173879d95f585c26070f 100644 (file)
@@ -46,6 +46,7 @@
 # include <sys/select.h>
 #endif
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -156,6 +157,9 @@ main (int argc, char **argv)
   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;
index 551b5350a948136e4cc6c49890e4f0f44f63dbda..3d72280049a7b9040faeedf9fbef36668fd2fa8f 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -215,6 +216,9 @@ main (int argc, char *argv[])
   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)
index c7a10f7fced432bf3753340108c6a7e49fd5ad95..10a55fa6d12a776323578ca827e86a493b6bddba 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <fnmatch.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -152,6 +153,9 @@ main (int argc, char **argv)
   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;
index 0592713e83fc47f4a8568780149248d7d6add569..d888ba507afba762b52665034a4dbc2508e59990 100644 (file)
@@ -69,6 +69,7 @@
 # define HAVE_DIR 0
 #endif
 
+#include "closeout.h"
 #include "error.h"
 #include "error-progname.h"
 #include "progname.h"
@@ -173,6 +174,9 @@ main (int argc, char **argv)
   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;
index a2e3591c4e369cfe6ba4e8adc74d4cc90342e524..0ff02625cd4e1c87b40f6a0f52c8dab833eb3c75 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
 #include "error-progname.h"
@@ -159,6 +160,9 @@ main (int argc, char **argv)
   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;
index 6e6b54b497d056d4ba2b6fe70e87056216b7f4ef..e6ce82468ff61d7b9f11529e7cd658a3a70a6a05 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "error.h"
 #include "error-progname.h"
 #include "progname.h"
@@ -115,6 +116,9 @@ main (int argc, char **argv)
   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)
index b3fe4f357d26be11dd1271e84d3bb234cf3ce42e..c12e87097dcf4bb9e20864eb8827325c35f0f76e 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "dir-list.h"
 #include "str-list.h"
 #include "error.h"
@@ -112,6 +113,9 @@ main (int argc, char **argv)
   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;
index ea95bc66744cc86c98621b25a075abbc2c3f8a6b..3adb5a21c828d853ec264b727dde68e61cac8e70 100644 (file)
@@ -33,6 +33,7 @@
 # include <unistd.h>
 #endif
 
+#include "closeout.h"
 #include "error.h"
 #include "error-progname.h"
 #include "progname.h"
@@ -101,6 +102,9 @@ main (int argc, char *argv[])
   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;
index 9120f211c581b87433647777089b76b3a28ef622..985179e028ca46f8e54b1813e18dab5c022b92ff 100644 (file)
@@ -1094,7 +1094,9 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
   if (fflush (fp) || ferror (fp))
     error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"),
           filename);
-  fclose (fp);
+
+  if (fp != stdout)
+    fclose (fp);
 }
 
 
index 63e51c982288b745285f202bc3732d5d34b4c274..0cd07abeba07f7c3bff1864a29da6346a0a7930f 100644 (file)
@@ -32,6 +32,7 @@
 #include <limits.h>
 
 #include "xgettext.h"
+#include "closeout.h"
 #include "dir-list.h"
 #include "file-list.h"
 #include "str-list.h"
@@ -249,6 +250,9 @@ main (int argc, char *argv[])
   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;
index 7273943062081c103067d93c4bd4359d5b1c6788..1f0acbe7933a9f8c4b065d281d4f86526420a011 100644 (file)
@@ -1,3 +1,11 @@
+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.
index e8b163273dac0933d4ab63584b31c93ac49fca5c..3b2d9d2278c9a549091ddcbcc70c45fffeb2616d 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <locale.h>
 
+#include "closeout.h"
 #include "error.h"
 #include "progname.h"
 #include "relocatable.h"
@@ -96,6 +97,9 @@ main (int argc, char *argv[])
   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)
index bea4cabfde3e0ed58df1fa8960bb3027a0d1b916..0060ae0d0b48d0df9715aedcc6c054c48857e47a 100644 (file)
@@ -26,6 +26,7 @@
 #include <locale.h>
 #include <errno.h>
 
+#include "closeout.h"
 #include "error.h"
 #include "progname.h"
 #include "relocatable.h"
@@ -85,6 +86,9 @@ main (int argc, char *argv[])
   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)
index 55f3d457766d218e10d341b7011ad0fdab3ed66e..96c6653f97a757576ce0e7f552740c5677cffbc7 100644 (file)
@@ -26,6 +26,7 @@ c_isupper
 c_isxdigit
 c_tolower
 c_toupper
+close_stdout
 compile_java_class
 concatenated_pathname
 copy_file_preserving