The Linux Programming Interface

(nextflipdebug5) #1
Terminals 1311

t.c_cc[VMIN] = 1; / Character-at-a-time input /
t.c_cc[VTIME] = 0; / with blocking /


if (tcsetattr(fd, TCSAFLUSH, &t) == -1)
return -1;


return 0;
}


/ Place terminal referred to by 'fd' in raw mode (noncanonical mode
with all input and output processing disabled). Return 0 on success,
or -1 on error. If 'prevTermios' is non-NULL, then use the buffer to
which it points to return the previous terminal settings.
/


int
ttySetRaw(int fd, struct termios *prevTermios)
{
struct termios t;


if (tcgetattr(fd, &t) == -1)
return -1;


if (prevTermios != NULL)
*prevTermios = t;


t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO);
/ Noncanonical mode, disable signals, extended
input processing, and echoing
/


t.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR |
INPCK | ISTRIP | IXON | PARMRK);
/ Disable special handling of CR, NL, and BREAK.
No 8th-bit stripping or parity error handling.
Disable START/STOP output flow control.
/


t.c_oflag &= ~OPOST; / Disable all output processing /


t.c_cc[VMIN] = 1; / Character-at-a-time input /
t.c_cc[VTIME] = 0; / with blocking /


if (tcsetattr(fd, TCSAFLUSH, &t) == -1)
return -1;


return 0;
}
–––––––––––––––––––––––––––––––––––––––––––––––––––––––tty/tty_functions.c


A program that places the terminal in raw or cbreak mode must be careful to
return the terminal to a usable mode when it terminates. Among other tasks, this
entails handling all of the signals that are likely to be sent to the program, so that

Free download pdf