diff options
| author | Pádraig Brady <P@draigBrady.com> | 2025-10-22 13:53:46 +0100 |
|---|---|---|
| committer | Pádraig Brady <P@draigBrady.com> | 2025-10-22 15:53:06 +0100 |
| commit | 5971f450b5abffd5a335a8937d6d588431137594 (patch) | |
| tree | 02691c5bdd81210050ca0ca5ae06cfbb239d11fc /src | |
| parent | install: prefer posix_spawnp to fork and execlp (diff) | |
| download | coreutils-5971f450b5abffd5a335a8937d6d588431137594.tar.gz coreutils-5971f450b5abffd5a335a8937d6d588431137594.zip | |
numfmt: promptly diagnose write errors
* src/numfmt.c (process line): Inspect the stdio error state when
outputting each line so that we don't have to check each output function
but do eventually exit upon write error, while also remaining buffered.
(main): Also check when outputting a header for the edge case
of very long headers.
* tests/misc/write-errors.sh: Enable the numfmt test case.
* NEWS: Mention the improvement, and reorganize all numfmt improvements.
Diffstat (limited to 'src')
| -rw-r--r-- | src/numfmt.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/numfmt.c b/src/numfmt.c index 5a1e94570..1ae831ba3 100644 --- a/src/numfmt.c +++ b/src/numfmt.c @@ -1512,6 +1512,9 @@ process_line (char *line, bool newline) if (newline) putchar (line_delim); + if (ferror (stdout)) + write_error (); + return valid_number; } @@ -1710,7 +1713,10 @@ main (int argc, char **argv) while (header-- && getdelim (&line, &line_allocated, line_delim, stdin) > 0) - fputs (line, stdout); + { + if (fputs (line, stdout) == EOF) + write_error (); + } while ((len = getdelim (&line, &line_allocated, line_delim, stdin)) > 0) |
