From: Pádraig Brady Date: Thu, 23 Jun 2016 13:15:59 +0000 (+0100) Subject: yes: handle short writes X-Git-Tag: v8.26~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5845664c8c61faf004eb3ef9979e770f794108c1;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/NEWS b/NEWS index 71b5c24ed0..b6c5c06efb 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 a3b25ce089..8e9b23c40d 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