]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(close_output_file): Check ferror before calling fclose.
authorJim Meyering <jim@meyering.net>
Sat, 13 Dec 1997 23:38:53 +0000 (23:38 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 13 Dec 1997 23:38:53 +0000 (23:38 +0000)
(main): Close stdout and check for errors.

src/csplit.c

index b0c6d6515668322cac31ed6b342d0a4b4d6d926b..4271ed4051e9c49daffe1e1761015e973cc1cca1 100644 (file)
@@ -1015,7 +1015,7 @@ close_output_file (void)
 {
   if (output_stream)
     {
-      if (fclose (output_stream) == EOF)
+      if (ferror (output_stream) || fclose (output_stream) == EOF)
        {
          error (0, errno, _("write error for `%s'"), output_filename);
          output_stream = NULL;
@@ -1028,8 +1028,12 @@ close_output_file (void)
          files_created--;
        }
       else
-        if (!suppress_count)
-         fprintf (stdout, "%d\n", bytes_written);
+       {
+         /* FIXME: if we write to stdout here, we have to close stdout
+            and check for errors.  */
+         if (!suppress_count)
+           fprintf (stdout, "%d\n", bytes_written);
+       }
       output_stream = NULL;
     }
 }
@@ -1507,6 +1511,9 @@ main (int argc, char **argv)
       cleanup_fatal ();
     }
 
+  if (!suppress_count && (ferror (stdout) || fclose (stdout) == EOF))
+    error (EXIT_FAILURE, errno, _("write error"));
+
   exit (EXIT_SUCCESS);
 }