about summary refs log tree commit diff
path: root/mscan.c
diff options
context:
space:
mode:
Diffstat (limited to 'mscan.c')
-rw-r--r--mscan.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/mscan.c b/mscan.c
index 52ba9a4..4052f1f 100644
--- a/mscan.c
+++ b/mscan.c
@@ -1,6 +1,9 @@
 #ifndef _XOPEN_SOURCE
 #define _XOPEN_SOURCE 700
 #endif
+#ifdef __sun
+#define __EXTENSIONS__ /* to get TIOCGWINSZ */
+#endif
 
 #include "xpledge.h"
 
@@ -19,6 +22,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <wchar.h>
+#include <termios.h>
 
 #include "blaze822.h"
 #include "u8decode.h"
@@ -571,9 +575,13 @@ main(int argc, char *argv[])
 
 	struct winsize w;
 	int ttyfd = open("/dev/tty", O_RDONLY | O_NOCTTY);
-	if (ttyfd >= 0 && ioctl(ttyfd, TIOCGWINSZ, &w) == 0) {
-		cols = w.ws_col;
+	if (ttyfd >= 0) {
+		if (ioctl(ttyfd, TIOCGWINSZ, &w) == 0)
+			cols = w.ws_col;
+		close(ttyfd);
+	}
 
+	if (isatty(1)) {
 		char *pg;
 		pg = getenv("MBLAZE_PAGER");
 		if (!pg)
@@ -586,8 +594,6 @@ main(int argc, char *argv[])
 				    pg, strerror(errno));
 		}
 	}
-	if (ttyfd >= 0)
-		close(ttyfd);
 
 	xpledge("stdio rpath", "");