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

all: avoid duplicated write errors on FreeBSD

* src/system.h (write_error): Also call fpurge(), which was seen to
be needed on FreeBSD 13.1 to avoid duplicated write errors.
* src/head.c (xwrite_stdout): Likewise.
* bootstrap.conf: Depend on fpurge.
Reported by Bruno Haible.
This commit is contained in:
Pádraig Brady
2023-08-27 16:01:27 +01:00
parent 13e13107e1
commit 5e44ad4e6d
3 changed files with 5 additions and 2 deletions

View File

@@ -104,6 +104,7 @@ gnulib_modules="
fnmatch-gnu
fopen-safer
fprintftime
fpurge
free-posix
freopen
freopen-safer

View File

@@ -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"));
}

View File

@@ -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"));
}