diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-06-23 14:15:59 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-06-24 01:13:33 +0100 |
commit | 5845664c8c61faf004eb3ef9979e770f794108c1 (patch) | |
tree | 98678dd3dae0f06cef11ae07b03b3471911e16d2 /src | |
parent | ba5767c2b869dcbbae91f1d42b488dca31652a0a (diff) | |
download | coreutils-5845664c8c61faf004eb3ef9979e770f794108c1.tar.xz |
yes: handle short writes
* src/yes.c (main): Loop over the write buffer to
handle the case where write may write less than requested.
* NEWS: Mention the bug fix.
Reported by Paul Eggert.
Diffstat (limited to 'src')
-rw-r--r-- | src/yes.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -101,12 +101,22 @@ main (int argc, char **argv) memcpy (pbuf, pbuf - line_len, line_len); pbuf += line_len; } - - while (0 <= write (STDOUT_FILENO, buf, pbuf - buf)) - continue; - - error (0, errno, _("standard output")); - return EXIT_FAILURE; + } + while (operandp == operand_lim) + { + char const* pwrite = buf; + size_t to_write = pbuf - buf; + while (to_write) + { + ssize_t written = write (STDOUT_FILENO, pwrite, to_write); + if (written < 0) + { + error (0, errno, _("standard output")); + return EXIT_FAILURE; + } + to_write -= written; + pwrite += written; + } } /* If the data doesn't fit in BUFSIZ then output |