Browse code

Allow -1 timeout to mean infinite

John Hawthorn authored on 16/09/2018 00:15:42
Showing 2 changed files

... ...
@@ -96,7 +96,7 @@ char tty_getchar(tty_t *tty) {
96 96
 	}
97 97
 }
98 98
 
99
-int tty_input_ready(tty_t *tty, unsigned long timeout, int return_on_signal) {
99
+int tty_input_ready(tty_t *tty, long int timeout, int return_on_signal) {
100 100
 	fd_set readfs;
101 101
 	FD_ZERO(&readfs);
102 102
 	FD_SET(tty->fdin, &readfs);
... ...
@@ -108,7 +108,13 @@ int tty_input_ready(tty_t *tty, unsigned long timeout, int return_on_signal) {
108 108
 	if (!return_on_signal)
109 109
 		sigaddset(&mask, SIGWINCH);
110 110
 
111
-	int err = pselect(tty->fdin + 1, &readfs, NULL, NULL, &ts, &mask);
111
+	int err = pselect(
112
+			tty->fdin + 1,
113
+			&readfs,
114
+			NULL,
115
+			NULL,
116
+			timeout < 0 ? NULL : &ts,
117
+			return_on_signal ? NULL : &mask);
112 118
 
113 119
 	if (err < 0) {
114 120
 		return 0;
... ...
@@ -17,7 +17,7 @@ void tty_close(tty_t *tty);
17 17
 void tty_init(tty_t *tty, const char *tty_filename);
18 18
 void tty_getwinsz(tty_t *tty);
19 19
 char tty_getchar(tty_t *tty);
20
-int tty_input_ready(tty_t *tty, int timeout, int return_on_signal);
20
+int tty_input_ready(tty_t *tty, long int timeout, int return_on_signal);
21 21
 
22 22
 void tty_setfg(tty_t *tty, int fg);
23 23
 void tty_setinvert(tty_t *tty);