From 444c6da14493b42305fa34183f199e8c6b366b0c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 13 Dec 1997 23:38:53 +0000 Subject: [PATCH] (close_output_file): Check ferror before calling fclose. (main): Close stdout and check for errors. --- src/csplit.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/csplit.c b/src/csplit.c index b0c6d65156..4271ed4051 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -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); } -- 2.47.2