* src/grep.c (prline): When line buffered, if there is a write error, report it immediately rather than waiting until the next line of output. --- src/grep.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/grep.c b/src/grep.c index 06f315d..696f4ce 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1180,6 +1180,9 @@ prline (char *beg, char *lim, char sep) if (!only_matching && lim > beg) fwrite (beg, 1, lim - beg, stdout); + if (line_buffered) + fflush (stdout); + if (ferror (stdout)) { write_error_seen = true; @@ -1187,9 +1190,6 @@ prline (char *beg, char *lim, char sep) } lastout = lim; - - if (line_buffered) - fflush (stdout); } /* Print pending lines of trailing context prior to LIM. Trailing context ends -- 2.5.0