1292 Chapter 62
The fd argument is a file descriptor that refers to a terminal. (If fd doesn’t refer to a
terminal, these functions fail with the error ENOTTY.)
The termios_p argument is a pointer to a termios structure, which records termi-
nal attributes:
struct termios {
tcflag_t c_iflag; /* Input flags */
tcflag_t c_oflag; /* Output flags */
tcflag_t c_cflag; /* Control flags */
tcflag_t c_lflag; /* Local modes */
cc_t c_line; /* Line discipline (nonstandard)*/
cc_t c_cc[NCCS]; /* Terminal special characters */
speed_t c_ispeed; /* Input speed (nonstandard; unused) */
speed_t c_ospeed; /* Output speed (nonstandard; unused) */
};
The first four fields of the termios structure are bit masks (the tcflag_t data type is an
integer type of suitable size) containing flags that control various aspects of the ter-
minal driver’s operation:
z c_iflag contains flags controlling terminal input;
z c_oflag contains flags controlling terminal output;
z c_cflag contains flags relating to hardware control of the terminal line; and
z c_lflag contains flags controlling the user interface for terminal input.
All of the flags used in the above fields are listed in Table 62-2 (on page 1302).
The c_line field specifies the line discipline for this terminal. For the purposes
of programming terminal emulators, the line discipline will always be set to N_TTY,
the so-called new discipline, a component of the kernel terminal-handling code that
implements canonical mode I/O processing. Setting the line discipline can be rele-
vant when programming serial lines.
The c_cc array contains the terminal special characters (interrupt, suspend, and
so on) as well as fields controlling the operation of noncanonical mode input. The
cc_t data type is an unsigned integer type suitable for holding these values, and the
NCCS constant specifies the number of elements in this array. We describe the termi-
nal special characters in Section 62.4.
The c_ispeed and c_ospeed fields are unused on Linux (and are not specified in
SUSv3). We explain how Linux stores terminal line speeds in Section 62.7.
The Seventh Edition and early BSD terminal driver (known as the tty driver)
had grown over time so that it used no less than four different data structures
to represent the information equivalent to the termios structure. System V
replaced this baroque arrangement with a single structure called termio. The
initial POSIX committee selected the System V API almost as is, in the process
renaming it to termios.