1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-03-21 20:34:25 +02:00

Ensure that no close failure goes unreported.

(close_stdout): Always close stdout.  I.e., don't
return early when it seems there's nothing to flush.
Don't include __fpending.h.
This commit is contained in:
Jim Meyering
2004-11-06 22:37:23 +00:00
parent d73a00981c
commit d77d7fe158

View File

@@ -32,7 +32,6 @@
#include "error.h"
#include "exitfail.h"
#include "quotearg.h"
#include "__fpending.h"
#if USE_UNLOCKED_IO
# include "unlocked-io.h"
@@ -49,7 +48,7 @@ close_stdout_set_file_name (const char *file)
}
/* Close standard output, exiting with status 'exit_failure' on failure.
If a program writes *anything* to stdout, that program should `fflush'
If a program writes *anything* to stdout, that program should close
stdout and make sure that it succeeds before exiting. Otherwise,
suppose that you go to the extreme of checking the return status
of every function that does an explicit write to stdout. The last
@@ -57,11 +56,9 @@ close_stdout_set_file_name (const char *file)
the fclose(stdout) could still fail (due e.g., to a disk full error)
when it tries to write out that buffered data. Thus, you would be
left with an incomplete output file and the offending program would
exit successfully.
FIXME: note the fflush suggested above is implicit in the fclose
we actually do below. Consider doing only the fflush and/or using
setvbuf to inhibit buffering.
exit successfully. Even calling fflush is not always sufficient,
since some file systems (NFS and CODA) buffer written/flushed data
until an actual close call.
Besides, it's wasteful to check the return value from every call
that writes to stdout -- just let the internal stream state record
@@ -76,11 +73,6 @@ close_stdout (void)
{
int e = ferror (stdout) ? 0 : -1;
/* If the stream's error bit is clear and there is nothing to flush,
then return right away. */
if (e && __fpending (stdout) == 0)
return;
if (fclose (stdout) != 0)
e = errno;