6cb91d81380b355eedde4ff4651923aae0b26282
[oftp] / src / unix / input.c
1 #include <errno.h>
2 #include <sys/select.h>
3 #include <curses.h>
4 #include "input.h"
5
6 int init_input(void)
7 {
8         nodelay(stdscr, TRUE);
9         return 0;
10 }
11
12 void cleanup_input(void)
13 {
14 }
15
16 int poll_input(union event *ev)
17 {
18         ev->type = EV_KEY;
19         ev->key.key = getch();
20         return 1;
21 }
22
23 int have_input(void)
24 {
25         fd_set rdset;
26         struct timeval tv = {0, 0};
27
28         FD_ZERO(&rdset);
29         FD_SET(0, &rdset);
30
31         while(select(1, &rdset, 0, 0, &tv) == -1 && errno == EINTR);
32
33         if(FD_ISSET(0, &rdset)) {
34                 return 1;
35         }
36         return 0;
37 }