Whamcloud - gitweb
libss: Fix warn_unused_result warnings from gcc
authorTheodore Ts'o <tytso@mit.edu>
Wed, 22 Apr 2009 18:48:59 +0000 (14:48 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 22 Apr 2009 18:48:59 +0000 (14:48 -0400)
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>
lib/ss/pager.c

index ca05519..67fc104 100644 (file)
@@ -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);
 }