From 935a123f3b9156e18d1397a05e5b5f1a5e021f22 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 22 Apr 2009 14:48:59 -0400 Subject: 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" --- lib/ss/pager.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/ss/pager.c b/lib/ss/pager.c index ca05519c..67fc1044 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); } -- cgit v1.2.3