]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
yes: handle short writes
authorPádraig Brady <P@draigBrady.com>
Thu, 23 Jun 2016 13:15:59 +0000 (14:15 +0100)
committerPádraig Brady <P@draigBrady.com>
Fri, 24 Jun 2016 00:13:33 +0000 (01:13 +0100)
* 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.

NEWS
src/yes.c

diff --git a/NEWS b/NEWS
index 71b5c24ed09f4f079ade8154b05b77267799fbdf..b6c5c06efbba2825f25102a68a52c1ef99eb634a 100644 (file)
--- 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
index a3b25ce08912de099f000883f86f2aead976dc30..8e9b23c40dbf8bd18b35878a256ce05db1f82416 100644 (file)
--- 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