Updated: April 19, 2023 |
Change the terminal control settings for a device
#include <termios.h> int tcsetattr( int filedes, int optional_actions, const struct termios *termios_p );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The tcsetattr() function sets the current terminal control settings for the opened device indicated by filedes to the values stored in the structure pointed to by termios_p.
The operation of tcsetattr() depends on the values in optional_actions:
The termios control structure is defined in <termios.h>. For more information, see tcgetattr().
#include <stdlib.h> #include <termios.h> int raw( int fd ) { struct termios termios_p; if( tcgetattr( fd, &termios_p ) ) return( -1 ); termios_p.c_cc[VMIN] = 1; termios_p.c_cc[VTIME] = 0; termios_p.c_lflag &= ~( ECHO|ICANON|ISIG| ECHOE|ECHOK|ECHONL ); termios_p.c_oflag &= ~( OPOST ); return( tcsetattr( fd, TCSADRAIN, &termios_p ) ); } int unraw( int fd ) { struct termios termios_p; if( tcgetattr( fd, &termios_p ) ) return( -1 ); termios_p.c_lflag |= ( ECHO|ICANON|ISIG| ECHOE|ECHOK|ECHONL ); termios_p.c_oflag |= ( OPOST ); return( tcsetattr( fd, TCSADRAIN, &termios_p ) ); } int main( void ) { raw( 0 ); /* * Stdin is now "raw" */ unraw ( 0 ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |