summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-06-03 10:34:51 -0400
committerJune McEnroe <june@causal.agency>2022-06-03 10:34:51 -0400
commitae064a619bb3972f0c12840e7d8950ac025fea1c (patch)
tree7cf68687e97d4541ee7ce2a5a1b56a62554a464f /bin
parentSet TABSIZE=4 (diff)
downloadsrc-ae064a619bb3972f0c12840e7d8950ac025fea1c.tar.gz
src-ae064a619bb3972f0c12840e7d8950ac025fea1c.zip
Stop polling stdin after EOF
Diffstat (limited to 'bin')
-rw-r--r--bin/qf.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/bin/qf.c b/bin/qf.c
index 0975cea8..aac44fa5 100644
--- a/bin/qf.c
+++ b/bin/qf.c
@@ -249,18 +249,22 @@ int main(int argc, char *argv[]) {
 	}
 	curse();
 	struct pollfd fds[2] = {
-		{ .fd = STDIN_FILENO, .events = POLLIN },
 		{ .fd = STDERR_FILENO, .events = POLLIN },
+		{ .fd = STDIN_FILENO, .events = POLLIN },
 	};
+	int nfds = 2;
 	size_t len = 0;
 	size_t cap = 4096;
 	char *buf = malloc(cap);
 	if (!buf) err(EX_OSERR, "malloc");
-	while (poll(fds, 2, -1)) {
+	while (poll(fds, nfds, -1)) {
 		if (fds[0].revents) {
-			ssize_t n = read(fds[0].fd, &buf[len], cap - len);
+			input();
+		}
+		if (nfds > 1 && fds[1].revents) {
+			ssize_t n = read(fds[1].fd, &buf[len], cap - len);
 			if (n < 0) err(EX_IOERR, "read");
-			if (!n) fds[0].events = 0;
+			if (!n) nfds--;
 			len += n;
 			char *ptr = buf;
 			for (
@@ -280,9 +284,6 @@ int main(int argc, char *argv[]) {
 				if (!buf) err(EX_OSERR, "realloc");
 			}
 		}
-		if (fds[1].revents) {
-			input();
-		}
 		draw();
 	}
 	err(EX_IOERR, "poll");