summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--src/yes.c22
2 files changed, 19 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 71b5c24ed..b6c5c06ef 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,9 @@ GNU coreutils NEWS -*- outline -*-
seq now immediately exits upon write errors.
[This bug was present in "the beginning".]
+ yes now handles short writes, rather than assuming all writes complete.
+ [bug introduced in coreutils-8.24]
+
** Changes in behavior
seq no longer accepts 0 value as increment, and now also rejects NaN
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