X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fclosein.c;h=4450d5bd8dd6be0a2fdd290942ad2773a916b001;hb=dd6ceef65e424d30db8706273f88c20b015012ce;hp=1aade1d18f69f0bcdef00d82dabbdfaad85a52aa;hpb=cc133e1865af68b87b61e558fa5e40a302f60c76;p=gnulib.git diff --git a/lib/closein.c b/lib/closein.c index 1aade1d18..4450d5bd8 100644 --- a/lib/closein.c +++ b/lib/closein.c @@ -19,7 +19,6 @@ #include #include "closein.h" -#include "closeout.h" #include #include @@ -30,6 +29,7 @@ #define _(msgid) gettext (msgid) #include "close-stream.h" +#include "closeout.h" #include "error.h" #include "exitfail.h" #include "quotearg.h" @@ -79,18 +79,23 @@ void close_stdin (void) { bool fail = false; + + /* Only attempt flush if stdin is seekable, as fflush is entitled to + fail on non-seekable streams. */ + if (fseeko (stdin, 0, SEEK_CUR) == 0 && fflush (stdin) != 0) + fail = true; if (close_stream (stdin) != 0) + fail = true; + if (fail) { + /* Report failure, but defer exit until after closing stdout, + since the failure report should still be flushed. */ char const *close_error = _("error closing file"); if (file_name) error (0, errno, "%s: %s", quotearg_colon (file_name), close_error); else error (0, errno, "%s", close_error); - - /* Defer failure until after closing stdout, since the output - can still usefully be flushed. */ - fail = true; } close_stdout ();