]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
fwriteerror now calls fclose().
authorBruno Haible <bruno@clisp.org>
Thu, 13 Jan 2005 12:12:38 +0000 (12:12 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:03 +0000 (12:12 +0200)
12 files changed:
gettext-tools/lib/ChangeLog
gettext-tools/lib/closeout.c
gettext-tools/lib/fwriteerror.c
gettext-tools/lib/fwriteerror.h
gettext-tools/src/ChangeLog
gettext-tools/src/write-csharp.c
gettext-tools/src/write-java.c
gettext-tools/src/write-mo.c
gettext-tools/src/write-po.c
gettext-tools/src/write-qt.c
gettext-tools/src/write-resources.c
gettext-tools/src/write-tcl.c

index e46f8beb6d8b1b179bfb5e4323d30b08ae315e20..6a6f9a729064e901c6e960417be784fb42009391 100644 (file)
@@ -1,3 +1,11 @@
+2005-01-06  Bruno Haible  <bruno@clisp.org>
+
+       * fwriteerror.h (fwriteerror): Change specification to include fclose.
+       * fwriteerror.c: Include <stdbool.h>.
+       (fwriteerror): At the end, close the file stream. Record whether
+       stdout was already closed.
+       * closeout.c: Update comments.
+
 2005-01-06  Bruno Haible  <bruno@clisp.org>
 
        * strerror.c: Update from gnulib, with HAVE_STRERROR modifications.
index 2f0ba105e10f2158ed3ef2d38f830bd50d68d429..a1f6d973544f3a5e4afafc8a7be001db5a59db44 100644 (file)
@@ -1,5 +1,5 @@
 /* closeout.c - close standard output
-   Copyright (C) 1998-2003 Free Software Foundation, Inc.
+   Copyright (C) 1998-2005 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
@@ -37,7 +37,7 @@
 #define _(msgid) gettext (msgid)
 
 /* Close standard output, exiting with status STATUS on failure.
-   If a program writes *anything* to stdout, that program should `fflush'
+   If a program writes *anything* to stdout, that program should close
    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
    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.
+   exit successfully.  Even calling fflush is not always sufficient,
+   since some file systems (NFS and CODA) buffer written/flushed data
+   until an actual close call.
 
    Besides, it's wasteful to check the return value from every call
    that writes to stdout -- just let the internal stream state record
@@ -64,10 +62,6 @@ close_stdout_status (int status)
 {
   if (fwriteerror (stdout))
     error (status, errno, "%s", _("write error"));
-  /* We don't need to fclose (stdout).  fwriteerror (stdout) == 0 guarantees
-     that the implicit fclose (stdout) at program exit will succeed.
-     This avoids a useless close(1) system call in the frequent case
-     that no error occurred.  */
 }
 
 /* Close standard output, exiting with status EXIT_FAILURE on failure.  */
index 364db8609372dd8087bd216a32414d8b5abd1329..97fbed261770dcb3258525d72c84d3b2b610a653 100644 (file)
@@ -1,5 +1,5 @@
 /* Detect write error on a stream.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003-2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
 #include "fwriteerror.h"
 
 #include <errno.h>
+#include <stdbool.h>
 
 int
 fwriteerror (FILE *fp)
 {
+  /* State to allow multiple calls to fwriteerror (stdout).  */
+  static bool stdout_closed = false;
+
+  if (fp == stdout && stdout_closed)
+    return 0;
+
   /* Need to
      1. test the error indicator of the stream,
-     2. flush the buffers (what fclose() would do), testing for error again.
-     We can equally well swap these steps; this leads to smaller code.  */
+     2. flush the buffers both in userland and in the kernel, through fclose,
+        testing for error again.  */
 
   /* Clear errno, so that on non-POSIX systems the caller doesn't see a
      wrong value of errno when we return -1.  */
   errno = 0;
 
-  if (fflush (fp))
-    return -1; /* errno is set here */
-
   if (ferror (fp))
     {
+      if (fflush (fp))
+       return -1; /* errno is set here */
       /* The stream had an error earlier, but its errno was lost.  If the
         error was not temporary, we can get the same errno by writing and
         flushing one more byte.  We can do so because at this point the
@@ -55,6 +61,13 @@ fwriteerror (FILE *fp)
       return -1;
     }
 
+  /* If we are closing stdout, don't attempt to do it later again.  */
+  if (fp == stdout)
+    stdout_closed = true;
+
+  if (fclose (fp))
+    return -1; /* errno is set here */
+
   return 0;
 }
 
@@ -109,10 +122,6 @@ main ()
          else
            fprintf (stderr, "Test %u:%u: fwriteerror found no error!\n",
                     i, j);
-
-         if (fclose (stream))
-           fprintf (stderr, "Test %u:%u: fclose failed, errno = %d\n",
-                    i, j, errno);
        }
     }
 
index 82cf5f18e3552008b63984d696585b723bef26a1..570023778875a4942ddac8461fedcb688e1ee474 100644 (file)
@@ -1,5 +1,5 @@
 /* Detect write error on a stream.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -22,7 +22,7 @@
      (a) Test the return value of every fwrite() or fprintf() call, and react
          immediately.
      (b) Just before fclose(), test the error indicator in the stream and
-         the return value of the final fflush() or fclose() call.
+         the return value of the final fclose() call.
 
    The benefit of (a) is that non file related errors (such that ENOMEM during
    fprintf) and temporary error conditions can be diagnosed accurately.
 
 #include <stdio.h>
 
-/* Write out the not yet written buffered contents of the stream FP, and then
-   test whether some error occurred on the stream FP.  FP must be a stream
-   opened for writing.
-   Return 0 if no error occurred.  In this case it can be assumed that
-   fclose (fp) will succeed.
+/* Write out the not yet written buffered contents of the stream FP, close
+   the stream FP, and test whether some error occurred on the stream FP.
+   FP must be a stream opened for writing.
+   Return 0 if no error occurred and fclose (fp) succeeded.
    Return -1 and set errno if there was an error.  The errno value will be 0
    if the cause of the error cannot be determined.
- */
+   For any given stream FP other than stdout, fwriteerror (FP) may only be
+   called once.  */
 extern int fwriteerror (FILE *fp);
index 5f324ff353b35563421f3de200df246b6f6bdfc3..4cf94b9e71041838e67adc3dd0d9909eb6513c51 100644 (file)
@@ -1,3 +1,14 @@
+2005-01-06  Bruno Haible  <bruno@clisp.org>
+
+       * write-csharp.c (msgdomain_write_csharp): Don't call fclose after
+       fwriteerror.
+       * write-java.c (msgdomain_write_java): Likewise.
+       * write-mo.c (msgdomain_write_mo): Likewise.
+       * write-po.c (msgdomain_list_print): Likewise.
+       * write-qt.c (msgdomain_write_qt): Likewise.
+       * write-resources.c (execute_writing_input): Likewise.
+       * write-tcl.c (msgdomain_write_tcl): Likewise.
+
 2005-01-05  Bruno Haible  <bruno@clisp.org>
 
        * msgattrib.c (main): Update year in --version output.
index e417f18ad533ced5c7e59d1a70556f7714b6ee60..3af2b74911e6a00faf30cc0e43f7a0d86df8a5f2 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing C# satellite assemblies.
-   Copyright (C) 2003-2004 Free Software Foundation, Inc.
+   Copyright (C) 2003-2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -770,7 +770,6 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
       fclose (csharp_file);
       goto quit5;
     }
-  fclose (csharp_file);
 
   /* Make it possible to override the .dll location.  This is
      necessary for running the testsuite before "make install".  */
index 230d28a9c2abdce1000bb259c5be91c6e938d595..2d3933b6b23719224a67455d0b602a3e3c8d0582 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing Java ResourceBundles.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -1085,7 +1085,6 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
       fclose (java_file);
       goto quit5;
     }
-  fclose (java_file);
 
   /* Compile the Java file to a .class file.
      directory must be non-NULL, because when the -d option is omitted, the
index 2bdb52afad9037a5c4fa35e91db2134ecd715eb8..4635bcc8f1582107bb51b5698a2c9f4ca5154be8 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing binary .mo files.
-   Copyright (C) 1995-1998, 2000-2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
 
    This program is free software; you can redistribute it and/or modify
@@ -725,9 +725,6 @@ msgdomain_write_mo (message_list_ty *mlp,
          if (fwriteerror (output_file))
            error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"),
                   file_name);
-
-         if (output_file != stdout)
-           fclose (output_file);
        }
     }
 
index 01dd0ff228190fcdd7831d98b600fef04c2f862e..05a136e5d07f20711612a57a9b69097cce4d3c62 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995-1998, 2000-2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -1125,9 +1125,6 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
   if (fwriteerror (fp))
     po_error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"),
              filename);
-
-  if (fp != stdout)
-    fclose (fp);
 }
 
 
index 95fabe350b0d45085fdfeded89de476524a48135..e28dfa9e80e39a10eb4e2d7aa542533bad409da4 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing Qt .qm files.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -529,9 +529,6 @@ strings, not in the untranslated strings\n")));
          if (fwriteerror (output_file))
            error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"),
                   file_name);
-
-         if (output_file != stdout)
-           fclose (output_file);
        }
     }
 
index 848f23bfeb0a67b6a88e9514b7e6f514fe4db915..5c4464920606076715ef0557d6433b2bd040fbe3 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing C# .resources files.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -95,7 +95,6 @@ execute_writing_input (const char *progname,
   if (fwriteerror (fp))
     error (EXIT_FAILURE, 0, _("error while writing to %s subprocess"),
           progname);
-  fclose (fp);
 
   /* Remove zombie process from process list, and retrieve exit status.  */
   /* He we can ignore SIGPIPE because WriteResource either writes to a file
index 77bab591c9284692c1974e1658f797ffc1f54bdb..9af659c14acb530e93687ac6952ca2978089b0c9 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing tcl/msgcat .msg files.
-   Copyright (C) 2002-2003 Free Software Foundation, Inc.
+   Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2002.
 
    This program is free software; you can redistribute it and/or modify
@@ -204,7 +204,6 @@ but the Tcl message catalog format doesn't support plural handling\n")));
       error (EXIT_FAILURE, errno, _("error while writing \"%s\" file"),
             file_name);
 
-    fclose (output_file);
     freesa (frobbed_locale_name);
   }