From: Theodore Ts'o Date: Wed, 22 Apr 2009 18:48:59 +0000 (-0400) Subject: libss: Fix warn_unused_result warnings from gcc X-Git-Tag: v1.41.5~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=935a123f3b9156e18d1397a05e5b5f1a5e021f22;p=thirdparty%2Fe2fsprogs.git libss: Fix warn_unused_result warnings from gcc Fixed a potential bug where by partial returns from the write system call could the fallback pager to drop characters. Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/ss/pager.c b/lib/ss/pager.c index ca05519c0..67fc10444 100644 --- a/lib/ss/pager.c +++ b/lib/ss/pager.c @@ -106,6 +106,25 @@ int ss_pager_create() } #endif +static int write_all(int fd, char *buf, size_t count) +{ + ssize_t ret; + int c = 0; + + while (count > 0) { + ret = write(fd, buf, count); + if (ret < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) + continue; + return -1; + } + count -= ret; + buf += ret; + c += ret; + } + return c; +} + void ss_page_stdin() { int i; @@ -127,7 +146,7 @@ void ss_page_stdin() char buf[80]; register int n; while ((n = read(0, buf, 80)) > 0) - write(1, buf, n); + write_all(1, buf, n); } exit(errno); }