summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2009-04-22 14:48:59 -0400
committerTheodore Ts'o <tytso@mit.edu>2009-04-22 14:48:59 -0400
commit935a123f3b9156e18d1397a05e5b5f1a5e021f22 (patch)
tree29b854eb354477c076a39df0ffcede6bfbba2a6c
parent9ea68828f31d5be1f6622321464533b35dd6d762 (diff)
downloade2fsprogs-935a123f3b9156e18d1397a05e5b5f1a5e021f22.tar.gz
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" <tytso@mit.edu>
-rw-r--r--lib/ss/pager.c21
1 files changed, 20 insertions, 1 deletions
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);
}