about summary refs log tree commit diff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2000-11-05 09:27:08 +0000
committerBart Schaefer <barts@users.sourceforge.net>2000-11-05 09:27:08 +0000
commitdbc0aebcd44a028ed5c5c392fa2b354a1b562955 (patch)
treee3257394a84f041ca00dee5a94faabc3ffdd59a9 /Src/utils.c
parentab99c6d8b67c7a30e696c0554e2e9a68719cabe0 (diff)
downloadzsh-dbc0aebcd44a028ed5c5c392fa2b354a1b562955.tar.gz
zsh-dbc0aebcd44a028ed5c5c392fa2b354a1b562955.tar.xz
zsh-dbc0aebcd44a028ed5c5c392fa2b354a1b562955.zip
Assorted read_poll() and zpty cleanup.
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/Src/utils.c b/Src/utils.c
index 05865cf67..1190347f7 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1315,7 +1315,7 @@ setblock_stdin(void)
 mod_export int
 read_poll(int fd, int *readchar, int polltty)
 {
-    int ret = 0;
+    int ret = -1;
     long mode = -1;
     char c;
 #ifdef HAVE_SELECT
@@ -1353,38 +1353,32 @@ read_poll(int fd, int *readchar, int polltty)
      */
     if (polltty) {
 	gettyinfo(&ti);
-	ti.tio.c_cc[VMIN] = 0;
-	settyinfo(&ti);
+	if ((polltty = ti.tio.c_cc[VMIN])) {
+	    ti.tio.c_cc[VMIN] = 0;
+	    settyinfo(&ti);
+	}
     }
 #else
     polltty = 0;
 #endif
 #ifdef HAVE_SELECT
-    if (!ret) {
-	expire_tv.tv_sec = expire_tv.tv_usec = 0;
-	FD_ZERO(&foofd);
-	FD_SET(fd, &foofd);
-	if (select(fd+1, (SELECT_ARG_2_T) &foofd, NULL, NULL, &expire_tv)
-	    > 1)
-	    ret = 1;
-    }
+    expire_tv.tv_sec = expire_tv.tv_usec = 0;
+    FD_ZERO(&foofd);
+    FD_SET(fd, &foofd);
+    ret = select(fd+1, (SELECT_ARG_2_T) &foofd, NULL, NULL, &expire_tv);
 #else
 #ifdef FIONREAD
-    if (!ret) {
-	ioctl(fd, FIONREAD, (char *)&val);
-	if (val)
-	    ret = 1;
-    }
+    if (ioctl(fd, FIONREAD, (char *) &val) == 0)
+	ret = (val > 0);
 #endif
 #endif
 
-    if (!ret) {
+    if (ret <= 0) {
 	/*
 	 * Final attempt: set non-blocking read and try to read a character.
 	 * Praise Bill, this works under Cygwin (nothing else seems to).
 	 */
-	if ((polltty || setblock_fd(0, fd, &mode))
-	    && read(fd, &c, 1) > 0) {
+	if ((polltty || setblock_fd(0, fd, &mode)) && read(fd, &c, 1) > 0) {
 	    *readchar = STOUC(c);
 	    ret = 1;
 	}
@@ -1397,7 +1391,7 @@ read_poll(int fd, int *readchar, int polltty)
 	settyinfo(&ti);
     }
 #endif
-    return ret;
+    return (ret > 0);
 }
 
 /**/