blob: f79b3c8ff9093452cd71d08c79f7f62026dab7b9 [file] [log] [blame]
sewardj8d365b52002-05-12 10:52:16 +00001
2/* A program which sets a readable fd to have a timeout, and therefore
3 needs --weird-hacks=ioctl-VTIME in order to run without
nethercote8b76fe52004-11-08 19:20:09 +00004 blocking.
5
6 [Nb: no longer true, since the ioctl-VTIME weird hack no longer exists]
7*/
sewardj8d365b52002-05-12 10:52:16 +00008
9#include <stdio.h>
10#include <sys/ioctl.h>
11#include <termio.h>
12
13int main ( void )
14{
njn25e49d8e72002-09-23 09:36:25 +000015 int c, i;
sewardj8d365b52002-05-12 10:52:16 +000016 int res;
17 struct termio tty, oldtty;
18
19 /**
20 ** Save the old tty settings, and get rid of echo
21 ** for the new tty settings
22 **/
23 ioctl(0, TCGETA, &oldtty);
24 tty = oldtty;
25 tty.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
26 tty.c_cc[VMIN] = 0;
27 tty.c_cc[VTIME] = 5;
28 res = ioctl(0, TCSETA, &tty);
29 printf("first ioctl returned %d\n", res);
30
31 /**
32 ** Now do whatever stuff you want non-echoed
33 **/
njn25e49d8e72002-09-23 09:36:25 +000034 i = 0;
35 while (i++ < 50) {
sewardj8d365b52002-05-12 10:52:16 +000036 c = getchar();
37 printf("got %d\n", c);
38 }
39
40 /**
41 ** Now reset the old settings
42 **/
43 res = ioctl(0, TCSETA, &oldtty);
44 printf("second ioctl returned %d\n", res);
45
46return 0;
47}