1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-20 10:51:48 +02:00

(close_output_file): Check ferror before calling fclose.

(main): Close stdout and check for errors.
This commit is contained in:
Jim Meyering
1997-12-13 23:38:53 +00:00
parent 84a050b56f
commit 444c6da144

View 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);
}