bug-coreutils
[Top][All Lists]
Advanced

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

'cat' doesn't check close(STDOUT_FILENO)'s return value


From: Paul Eggert
Subject: 'cat' doesn't check close(STDOUT_FILENO)'s return value
Date: Tue, 13 Dec 2005 17:43:56 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

On some operating systems, notices of output errors are sometimes
delayed until you close the file.  However, in the normal case
coreutils 'cat' doesn't check the return value from
'close(STDOUT_FILENO)'.  I installed this patch.

2005-12-13  Paul Eggert  <address@hidden>

        * src/cat.c (main): Check for close (STDOUT_FILENO) failure.

--- src/cat.c   11 Jul 2005 18:21:11 -0000      1.105
+++ src/cat.c   14 Dec 2005 01:39:46 -0000      1.106
@@ -555,7 +555,9 @@ main (int argc, char **argv)
   textdomain (PACKAGE);
 
   /* Arrange to close stdout if we exit via the
-     case_GETOPT_HELP_CHAR or case_GETOPT_VERSION_CHAR code.  */
+     case_GETOPT_HELP_CHAR or case_GETOPT_VERSION_CHAR code.
+     Normally STDOUT_FILENO is used rather than stdout, so
+     close_stdout does nothing.  */
   atexit (close_stdout);
 
   /* Parse command line options.  */
@@ -766,5 +768,8 @@ main (int argc, char **argv)
   if (have_read_stdin && close (STDIN_FILENO) < 0)
     error (EXIT_FAILURE, errno, _("closing standard input"));
 
+  if (close (STDOUT_FILENO) != 0)
+    error (EXIT_FAILURE, errno, _("write error"));
+
   exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }




reply via email to

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