commit 848b32408da9e65c1b3c8062c2432390ea4d16f9
parent ab0270b0e9e2f5323c5ee1f10ebec5bd3fd65a0c
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date: Sat, 8 Feb 2020 10:49:07 +0100
replace select(2) by poll(2)
Diffstat:
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/scroll.c b/scroll.c
@@ -19,13 +19,13 @@
#include <sys/types.h>
#include <sys/ioctl.h>
-#include <sys/select.h>
#include <sys/wait.h>
#include <sys/queue.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
+#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
@@ -237,23 +237,23 @@ main(int argc, char *argv[])
if (tcsetattr(STDIN_FILENO, TCSANOW, &new) == -1)
die("tcsetattr:");
- fd_set rd;
size_t size = BUFSIZ, pos = 0;
char *buf = calloc(size, sizeof *buf);
if (buf == NULL)
die("calloc:");
+ struct pollfd pfd[2] = {
+ {STDIN_FILENO, POLLIN, 0},
+ {mfd, POLLIN, 0}
+ };
+
for (;;) {
char c;
- FD_ZERO(&rd);
- FD_SET(STDIN_FILENO, &rd);
- FD_SET(mfd, &rd);
-
- if (select(mfd + 1, &rd, NULL, NULL, NULL) < 0 && errno != EINTR)
- die("select:");
+ if (poll(pfd, 2, 0) == -1 && errno != EINTR)
+ die("poll:");
- if (FD_ISSET(STDIN_FILENO, &rd)) {
+ if (pfd[0].revents & POLLIN) {
if (read(STDIN_FILENO, &c, 1) <= 0 && errno != EINTR)
die("read:");
if (c == 17) /* ^Q */
@@ -261,7 +261,7 @@ main(int argc, char *argv[])
else if (write(mfd, &c, 1) == -1)
die("write:");
}
- if (FD_ISSET(mfd, &rd)) {
+ if (pfd[1].revents & POLLIN) {
ssize_t n = read(mfd, &c, 1);
if (n == -1 && errno != EINTR)
die("read:");