diff options
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | src/uniq.c | 9 | ||||
| -rwxr-xr-x | tests/misc/write-errors.sh | 2 |
3 files changed, 8 insertions, 5 deletions
@@ -62,7 +62,7 @@ GNU coreutils NEWS -*- outline -*- irrespective of which kernel version coreutils is built against, reinstating that behaviour from coreutils-9.0. - od will now exit immediately upon receiving a write error, which is + od and uniq will now exit immediately upon receiving a write error, which is significant when reading large / unbounded inputs. split now uses more tuned access patterns for its potentially large input. diff --git a/src/uniq.c b/src/uniq.c index 15611540b..2dbec9fcd 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -309,7 +309,9 @@ writeline (struct linebuffer const *line, if (countmode == count_occurrences) printf ("%7" PRIuMAX " ", linecount + 1); - fwrite (line->buffer, sizeof (char), line->length, stdout); + if (fwrite (line->buffer, sizeof (char), line->length, stdout) + != line->length) + write_error (); } /* Process input file INFILE with output to OUTFILE. @@ -378,8 +380,9 @@ check_file (char const *infile, char const *outfile, char delimiter) if (new_group || grouping != GM_NONE) { - fwrite (thisline->buffer, sizeof (char), - thisline->length, stdout); + if (fwrite (thisline->buffer, sizeof (char), thisline->length, + stdout) != thisline->length) + write_error (); SWAP_LINES (prevline, thisline); prevfield = thisfield; diff --git a/tests/misc/write-errors.sh b/tests/misc/write-errors.sh index 31b6433d7..20942e068 100755 --- a/tests/misc/write-errors.sh +++ b/tests/misc/write-errors.sh @@ -46,7 +46,7 @@ tail -n+1 -z /dev/zero tee < /dev/zero tr . . < /dev/zero unexpand /dev/zero -# TODO: uniq -z -D /dev/zero +uniq -z -D /dev/zero yes " | sort -k 1b,1 > all_writers || framework_failure_ |
