This section describes the functions that are used to control the general terminal interface. Unless otherwise noted for a specific command, these functions are restricted from use by background processes. Attempts to perform these operations shall cause the process group to be sent a SIGTTOU signal. If the calling process is blocking or ignoring SIGTTOU signals, the process is allowed to perform the operation and the SIGTTOU signal is not sent.
In all the functions, although
fd is an open file descriptor, the functions affect the underlying terminal file, not just the open file description associated with the particular file descriptor.
The
cfmakeraw function sets the flags stored in the termios structure (initialized by
tcgetattr) to a state disabling all input and output processing, giving a “raw I/O path”. It should be noted that there is no function to reverse this effect. This is because there are a variety of processing options that could be re-enabled and the correct method is for an application to snapshot the current terminal state using the function
tcgetattr, setting raw mode with
cfmakeraw and the subsequent
tcsetattr, and then using another
tcsetattr with the saved state to revert to the previous terminal state.
The
tcgetattr function copies the parameters associated with the terminal referenced by
fd to the termios structure referenced by
tp. This function is allowed from a background process, however, the terminal attributes may be subsequently changed by a foreground process.
The
tcsetattr function sets the parameters associated with the terminal from the termios structure referenced by
tp. The
action field is created by
or'ing the following values, as specified in the include file
<termios.h>.
TCSANOW
The change occurs immediately.
TCSADRAIN
The change occurs after all output written to fd has been transmitted to the terminal. This value of action should be used when changing parameters that affect output.
TCSAFLUSH
The change occurs after all output written to fd has been transmitted to the terminal. Additionally, any input that has been received but not read is discarded.
TCSASOFT
If this value is or'ed into the action value, the values of the c_cflag, c_ispeed, and c_ospeed fields are ignored.
The 0 baud rate is used to terminate the connection. If 0 is specified as the output speed to the function
tcsetattr, modem control will no longer be asserted on the terminal, disconnecting the terminal.
If zero is specified as the input speed to the function
tcsetattr, the input baud rate will be set to the same value as that specified by the output baud rate.