Provides the terminal interface for the Berkeley line discipline.
The sgtty.h file defines the structures used by ioctl subroutines that apply to terminal files. The structures, definitions, and values in this file are provided for compatibility with the Berkeley user interface for asynchronous communication. Window and terminal size operations use the winsize structure, which is defined in the ioctl.h file. The winsize structure and the ioctl functions that use it are described in tty Subsystem Overview in AIX® Version 7.1 General Programming Concepts: Writing and Debugging Programs.
Basic sgtty.h Modes
Basic ioctl functions use the sgttyb structure defined in the sgtty.h file. This structure contains the following fields:
The delay bits specify how long transmission stops to allow for mechanical or other movement when certain characters are sent to the terminal. The actual delays depend on line speed and system load.
The EVENP and ODDP flags control both parity checking on input and parity generation on output in COOKED and CBREAK mode (unless the LPASS8 bit is enabled). Even parity is generated on output unless the ODDP flag is set and the EVENP flag is clear, in which case odd parity is generated. Input characters with the wrong parity, as determined by the EVENP and ODDP flags, are ignored in COOKED and CBREAK mode.
The RAW mode disables all processing except output flushing specified by the LFLUSHO bit. The full 8 bits of input are given as soon as they are available; all 8 bits are passed on output. A break condition in the input is reported as a null character. If the input queue overflows in RAW mode, all data in the input and output queues is discarded; this applies to both the new and old drivers.
Basic ioctl Operations
A large number of ioctl commands apply to terminals. Some have the general form:
#include <sgtty.h>
ioctl(FileDescriptor, Code, Value)
struct sgttyb *Value;
The applicable values for the Code parameter are:
Item | Description |
---|---|
TIOCGETP | Fetches the basic parameters associated with the terminal and stores them in the sgttyb structure that is pointed to. |
TIOCSETP | Sets the parameters according to the sgttyb structure that is pointed to. The interface delays until output stops, then throws away any unread characters before changing the modes. |
TIOCSETN | Has the same effect as the TIOCSETP value but does not delay or flush input. Input is not preserved, however, when changing to or from the RAW mode. |
For the following codes, the Value parameter is ignored:
Item | Description |
---|---|
TIOCEXCL | Sets exclusive-use mode; no further opens are permitted until the file is closed. |
TIOCNXCL | Turns off exclusive-use mode. |
TIOCHPCL | When the file is closed for the last time, hangs up the terminal. This is useful when the line is associated with a modem used to place outgoing calls. |
For the following code, the Value parameter is a pointer to an integer.
Item | Description |
---|---|
TIOCFLUSH | If the integer pointed to by the Value parameter has
a zero value, all characters waiting in input or output queues are
flushed. Otherwise, the value of the integer applies to the FREAD
and FWRITE bits defined in the fcntl.h file. If the FREAD bit
is set, all characters waiting in input queues are flushed. If the
FWRITE bit is set, all characters waiting in output queues are flushed.
Note: The FREAD and FWRITE bits cannot be used unless the _KERNEL flag is set.
|
In the following codes, the argument is 0 unless specified otherwise:
Item | Description |
---|---|
TIOCSTI | The Value parameter points to a character that the system pretends has been typed on the terminal. |
TIOCSBRK | The break bit is set in the terminal. |
TIOCCBRK | The break bit is cleared. |
TIOCSDTR | Data terminal ready is set. |
TIOCCDTR | Data terminal ready is cleared. |
TIOCSTOP | Output is stopped as if the stop character had been typed. |
TIOCSTART | Output is restarted as if the start character had been typed. |
TIOCGPGRP | The Value parameter is a pointer to an integer into which is placed the process group ID of the process group for which this terminal is the control terminal. |
TIOCSPGRP | The Value parameter is a pointer to an integer which is the value to which the process group ID for this terminal will be set. |
TIOCOUTQ | Returns in the integer pointed to by the Value parameter the number of characters queued for output to the terminal. |
TIONREAD | Returns in the integer pointed to by the Value parameter the number of characters immediately readable from the argument descriptor. This works for files, pipes, and terminals. |
Uppercase Terminals
If the LCASE output-mode bit is set, all uppercase letters are mapped into the corresponding lowercase letter. The uppercase letter can be generated by preceding it with a \ (backslash). Uppercase letters are preceded by a backslash when they are output. In addition, the following escape sequences can be generated on output and accepted on input:
For | Use |
---|---|
` (grave) | \' |
| | \! |
~ | \^ |
{ | \( |
} | \) |
To deal with terminals that do not understand that the ~ (tilde) has been made into an ASCII character, the LTILDE bit can be set in the local-mode word. When the LTILDE bit is set, the ~ (tilde) character will be replaced with the ` (grave) character on output.
Special Characters
A tchars structure associated with each terminal specifies special characters for both the old and new terminal interfaces. This structure is defined in the ioctl.h file, for which the sgtty.h file contains an #include statement. The tchars structure contains the following fields:
Item | Description |
---|---|
t_intrc | The interrupt character (Ctrl-C, by default) generates a SIGINT signal. This is the normal way to stop a process that is no longer needed or to regain control in an interactive program. |
t_quitc | The quit character (Ctrl-\, by default) generates a SIGQUIT signal. This is used to end a program and produce a core image, if possible, in a core file in the current directory. |
t_startc | The start-output character (Ctrl-Q, by default). |
t_stopc | The stop-output character (Ctrl-S, by default). |
t_eofc | The end-of-file character (Ctrl-D, by default). |
t_brkc | The input delimiter (-1, by default). This character acts like a newline in that it ends a line, is echoed, and is passed to the program. |
The stop and start characters can be the same to produce a toggle effect. The applicable ioctl functions are:
Item | Description |
---|---|
TIOCGETC | Gets the special characters and puts them in the specified structure. |
TIOCSETC | Sets the special characters to those given in the structure. |
Local Mode
Associated with each terminal is a local-mode word. The bits of the local-mode word are:
Item | Description |
---|---|
LCRTBS | Backspaces on erase rather than echoing erase. |
LPRTERA | Printing terminal erase mode. |
LCRTERA | Erases character echoes as Backspace-Space-Backspace. |
LTILDE | Converts ~ (tilde) to ` (grave) on output (for terminals that do not recognize the tilde as an ASCII character). |
LMDMBUF | Stops and starts output when carrier drops. |
LLITOUT | Suppresses output translations. |
LTOSTOP | Sends a SIGTTOU signal for background output. |
LFLUSHO | Output is being flushed. |
LNOHANG | Do not send hang up when carrier drops. |
LCRTKIL | Backspace-Space-Backspace to erase the entire line on line kill. |
LPASS8 | Passes all 8 bits through on input, in any mode. |
LCTLECH | Echoes input control characters as Ctrl-X, delete as Ctrl-?. |
LPENDIN | Retypes pending input at next read or input character. |
LDECCTQ | Only Ctrl-Q restarts output after a Ctrl-S. |
LNOFLSH | Inhibits flushing of pending I/O when an interrupt character is typed. |
The following ioctl functions operate on the local-mode word structure:
Item | Description |
---|---|
TIOCLBIS | The Value parameter is a pointer to an integer whose value is a mask containing the bits to be set in the local-mode word. |
TIOCLBIC | The Value parameter is a pointer to an integer whose value is a mask containing the bits to be cleared in the local-mode word. |
TIOCLSET | The Value parameter is a pointer to an integer whose value is stored in the local-mode word. |
TIOCLGET | The Value parameter is a pointer to an integer into which the current local-mode word is placed. |
Local Special Characters
The ltchars structure associated with each terminal defines control characters for the new terminal driver. This structure contains the following fields:
Item | Description |
---|---|
t_suspc | The suspend-process character (Ctrl-Z, by default). This sends a SIGTSTP signal to suspend the current process group. This character is recognized during input. |
t_dsuspc | The delayed suspend-process character (Ctrl-Y, by default). This sends a SIGTSTP signal to suspend the current process group. This character is recognized when the process attempts to read the control character rather than when the character is typed. |
t_rprntc | The reprint line-control character (Ctrl-R, by default). This reprints all characters that are preceded by a new-line character and have not been read. |
t_flushc | The flush-output character (Ctrl-O, by default). This flushes data that is written but not transmitted. |
t_werasc | The word-erase character (Ctrl-W, by default). This erases the preceding word. This does not erase beyond the beginning of the line. |
t_lnextc | The literal-next character (Ctrl-V, by default). This causes the special meaning of the next character to be ignored so that characters can be input without being interpreted by the system. |
The following ioctl functions, which use the ltchars structure, are supported by the terminal interface for the definition of local special characters for a terminal:
Item | Description |
---|---|
TIOCSLTC | Sets local characters. The argument to this function is a pointer to an ltchars structure, which defines the new local special characters. |
TIOCGLTC | Sets local characters. The argument to this function is a pointer to an ltchars structure into which is placed the current set of local special characters. |
The winsize structure and the ioctl functions that use it are described in the discussion of the tty common code in "tty Subsystem Overview" in AIX Version 7.1 General Programming Concepts: Writing and Debugging Programs.
Item | Description |
---|---|
/dev/tty | The tty special file, which is a synonym for the controlling terminal. |