/* sample unix system 5 set and reset raw mode with zero read delay */ #include #define SGTTY struct termio #include struct termio ttyold, ttynew; setraw () { iocttl (0, TCGETA, &ttyold); /* get termio structure for terminal */ ttynew = ttyold; /* copy termio structure for modification */ ttynew.c_oflag = ttynew.c_lflag = 0; /* raw mode */ /* omit "| IXON | IXOFF" on next line for full raw mode */ ttynew.c_iflag = IGNBRK | IGNPAR | IXON | IXOFF; /* with xon/xoff */ ttynew.c_cc[VTIME] = 0; /* max time to wait for a char ( in 0.1 sec) */ ttynew.c_cc[VMIN] = 0; /* number of chaaracters in shortest message */ ioctl (0, TCSETA, &ttynew); /* set termi structure for terminal */ } resetraw () { ioctl (0, TCSETA, &ttyold); /* reset termi structure for terminal */ } main() { setraw(); /* set terminal into raw mode, zero read delay */ /* in a statement of the following form: cur_bytes = read (0, buffer, max_bytes); cur_bytes will indicate the number of bytes (from 0 to max_bytes) transferred to buffer. */ resetraw(); /* if terminal is not reset, it will remain in raw mode */ }