diff --git a/bootstrap.conf b/bootstrap.conf index d758a9ff6..f968269de 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -104,6 +104,7 @@ gnulib_modules=" fnmatch-gnu fopen-safer fprintftime + fpurge free-posix freopen freopen-safer diff --git a/src/head.c b/src/head.c index 7bba1420c..da32c886f 100644 --- a/src/head.c +++ b/src/head.c @@ -181,6 +181,7 @@ xwrite_stdout (char const *buffer, size_t n_bytes) if (n_bytes > 0 && fwrite (buffer, 1, n_bytes, stdout) < n_bytes) { clearerr (stdout); /* To avoid redundant close_stdout diagnostic. */ + fpurge (stdout); error (EXIT_FAILURE, errno, _("error writing %s"), quoteaf ("standard output")); } diff --git a/src/system.h b/src/system.h index 7b736604b..7ba43bd21 100644 --- a/src/system.h +++ b/src/system.h @@ -769,8 +769,9 @@ static inline void write_error (void) { int saved_errno = errno; - fflush (stdout); /* Ensure nothing buffered that might induce an error. */ - clearerr (stdout); /* To avoid extraneous diagnostic from close_stdout. */ + fflush (stdout); /* Last attempt to write any buffered data. */ + fpurge (stdout); /* Ensure nothing buffered that might induce an error. */ + clearerr (stdout); /* Avoid extraneous diagnostic from close_stdout. */ error (EXIT_FAILURE, saved_errno, _("write error")); }