summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2016-06-23 14:15:59 +0100
committerPádraig Brady <P@draigBrady.com>2016-06-24 01:13:33 +0100
commit5845664c8c61faf004eb3ef9979e770f794108c1 (patch)
tree98678dd3dae0f06cef11ae07b03b3471911e16d2 /src
parentba5767c2b869dcbbae91f1d42b488dca31652a0a (diff)
downloadcoreutils-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.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/yes.c b/src/yes.c
index a3b25ce08..8e9b23c40 100644
--- a/src/yes.c
+++ b/src/yes.c
@@ -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