Whamcloud - gitweb
ext2fs: don't ignore return value in ext2fs_count_blocks
[tools/e2fsprogs.git] / lib / ss / pager.c
index ca05519..b9b8899 100644 (file)
@@ -14,6 +14,7 @@
  * express or implied warranty.
  */
 
+#include "config.h"
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -38,7 +39,6 @@ extern int errno;
 #endif
 
 static char MORE[] = "more";
-extern char *_ss_pager_name;
 extern char *getenv PROTOTYPE((const char *));
 
 char *ss_safe_getenv(const char *arg)
@@ -55,7 +55,9 @@ char *ss_safe_getenv(const char *arg)
 #endif
 #endif
 
-#ifdef HAVE___SECURE_GETENV
+#if defined(HAVE_SECURE_GETENV)
+       return secure_getenv(arg);
+#elif defined(HAVE___SECURE_GETENV)
        return __secure_getenv(arg);
 #else
        return getenv(arg);
@@ -106,7 +108,26 @@ int ss_pager_create()
 }
 #endif
 
-void ss_page_stdin()
+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(void)
 {
        int i;
        sigset_t mask;
@@ -127,7 +148,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);
 }