blob: a78de65dd8700f445840ae74c769a850be3960ac [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
4 blocking. */
5
6#include <stdio.h>
7#include <sys/ioctl.h>
8#include <termio.h>
9
10int main ( void )
11{
njn25e49d8e72002-09-23 09:36:25 +000012 int c, i;
sewardj8d365b52002-05-12 10:52:16 +000013 int res;
14 struct termio tty, oldtty;
15
16 /**
17 ** Save the old tty settings, and get rid of echo
18 ** for the new tty settings
19 **/
20 ioctl(0, TCGETA, &oldtty);
21 tty = oldtty;
22 tty.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
23 tty.c_cc[VMIN] = 0;
24 tty.c_cc[VTIME] = 5;
25 res = ioctl(0, TCSETA, &tty);
26 printf("first ioctl returned %d\n", res);
27
28 /**
29 ** Now do whatever stuff you want non-echoed
30 **/
njn25e49d8e72002-09-23 09:36:25 +000031 i = 0;
32 while (i++ < 50) {
sewardj8d365b52002-05-12 10:52:16 +000033 c = getchar();
34 printf("got %d\n", c);
35 }
36
37 /**
38 ** Now reset the old settings
39 **/
40 res = ioctl(0, TCSETA, &oldtty);
41 printf("second ioctl returned %d\n", res);
42
43return 0;
44}