bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proposed change to closeout module


From: Bruno Haible
Subject: proposed change to closeout module
Date: Fri, 29 Sep 2006 16:16:03 +0200
User-agent: KMail/1.9.1

Hi Paul and Jim,

The closeout module currently ignores write failures on stderr.
This patch makes it report failures on stderr through an exit status.


2006-09-29  Bruno Haible  <address@hidden>

        * modules/closeout (Description): Mention stderr too.
        * lib/closeout.c (close_stdout): Also close stderr.

diff -c -3 -r1.15 closeout
*** modules/closeout    21 Aug 2006 21:46:31 -0000      1.15
--- modules/closeout    29 Sep 2006 14:08:32 -0000
***************
*** 1,5 ****
  Description:
! Close standard output, exiting with a diagnostic on error.
  
  Files:
  lib/closeout.h
--- 1,5 ----
  Description:
! Close standard output and standard error, exiting with a diagnostic on error.
  
  Files:
  lib/closeout.h
diff -c -3 -r1.8 closeout.h
*** lib/closeout.h      14 May 2005 06:03:57 -0000      1.8
--- lib/closeout.h      29 Sep 2006 14:08:32 -0000
***************
*** 1,6 ****
! /* Close standard output.
  
!    Copyright (C) 1998, 2000, 2003, 2004 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
--- 1,6 ----
! /* Close standard output and standard error.
  
!    Copyright (C) 1998, 2000, 2003, 2004, 2006 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
diff -c -3 -r1.21 closeout.c
*** lib/closeout.c      13 Sep 2006 22:38:14 -0000      1.21
--- lib/closeout.c      29 Sep 2006 14:08:32 -0000
***************
*** 1,4 ****
! /* Close standard output, exiting with a diagnostic on error.
  
     Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006 Free
     Software Foundation, Inc.
--- 1,5 ----
! /* Close standard output and standard error, exiting with a diagnostic on
!    error.
  
     Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006 Free
     Software Foundation, Inc.
***************
*** 46,51 ****
--- 47,54 ----
  /* Close standard output.  On error, issue a diagnostic and _exit
     with status 'exit_failure'.
  
+    Also close standard error.  On error, _exit with status 'exit_failure'.
+ 
     Since close_stdout is commonly registered via 'atexit', POSIX
     and the C standard both say that it should not call 'exit',
     because the behavior is undefined if 'exit' is called more than
***************
*** 67,72 ****
--- 72,78 ----
  void
  close_stdout (void)
  {
+   /* Close standard output.  */
    if (close_stream (stdout) != 0)
      {
        char const *write_error = _("write error");
***************
*** 78,81 ****
--- 84,99 ----
  
        _exit (exit_failure);
      }
+ 
+   /* Close standard error.  This is simpler than fwriteerror_no_ebadf, because
+      upon failure we don't need an errno - all we can do at this point is to
+      set an exit status.  */
+   errno = 0; 
+   if (ferror (stderr) || fflush (stderr))
+     {
+       fclose (stderr);
+       _exit (exit_failure);
+     }
+   if (fclose (stderr) && errno != EBADF)
+     _exit (exit_failure);
  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]