Date: Tue, 13 Jun 2017 13:26:50 +0000 (UTC) From: Pietro Cerutti <gahr@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319898 - head/usr.bin/yes Message-ID: <201706131326.v5DDQorC097491@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gahr (ports committer) Date: Tue Jun 13 13:26:50 2017 New Revision: 319898 URL: https://svnweb.freebsd.org/changeset/base/319898 Log: Handle partial writes Reported by: ed Reviewed by: cognet Approved by: cognet Modified: head/usr.bin/yes/yes.c Modified: head/usr.bin/yes/yes.c ============================================================================== --- head/usr.bin/yes/yes.c Tue Jun 13 12:35:01 2017 (r319897) +++ head/usr.bin/yes/yes.c Tue Jun 13 13:26:50 2017 (r319898) @@ -55,6 +55,8 @@ main(int argc, char **argv) char * exp = y; size_t buflen = 0; size_t explen = sizeof(y); + size_t more; + ssize_t ret; if (caph_limit_stdio() < 0 || (cap_enter() < 0 && errno != ENOSYS)) err(1, "capsicum"); @@ -77,8 +79,10 @@ main(int argc, char **argv) explen = buflen; } - while (write(STDOUT_FILENO, exp, explen) > 0) - ; + more = explen; + while ((ret = write(STDOUT_FILENO, exp + (explen - more), more)) > 0) + if ((more -= ret) == 0) + more = explen; err(1, "stdout"); /*NOTREACHED*/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706131326.v5DDQorC097491>