@Go to the ‰ŠP�”›first@�”˜, ‰ŠP�”›previous@�”˜, ‰ŠP�”›next@�”˜, ‰ŠP�”›last@�”˜ section, ‰ŠP�”›table of contents@�”˜.
Œ

ˆ‰SEC232Št�”›Low-Level Terminal Interface

@�”˜This chapter describes functions that are specific to terminal devices. You can use these functions to do things like turn off input echoing; set serial line characteristics such as line speed and flow control; and change which characters are used for end-of-file, command-line editing, sending signals, and similar control functions.
Most of the functions in this chapter operate on file descriptors. See section ‰ŠP�”›Low-Level Input/Output@�”˜, for more information about what a file descriptor is and how to open a file descriptor for a terminal device.
ˆ‰SEC233Št�”›Identifying Terminals

‰IDX1115Š‰IDX1116Š
@�”˜The functions described in this chapter only work on files that correspond to terminal devices. You can find out whether a file descriptor is associated with a terminal by using the Hisatty@ function.
‰IDX1117Š@�”˜Prototypes for both Hisatty@ and Httyname@ are declared in the header file H`unistd.h'@.

AFunction:@ int Disatty@ B(int Bfiledes@)
Â‰IDX1118Š@�”˜This function returns H1@ if Bfiledes@ is a file descriptor associated with an open terminal device, and H0@ otherwise.À

If a file descriptor is associated with a terminal, you can get its associated file name using the Httyname@ function. See also the Hctermid@ function, described in section ‰ŠP�”›Identifying the Controlling Terminal@�”˜.

AFunction:@ char * Dttyname@ B(int Bfiledes@)
Â‰IDX1119Š@�”˜If the file descriptor Bfiledes@ is associated with a terminal device, the Httyname@ function returns a pointer to a statically-allocated, null-terminated string containing the file name of the terminal file. The value is a null pointer if the file descriptor isn't associated with a terminal, or the file name cannot be determined.À

ˆ‰SEC234Št�”›I/O Queues

@�”˜Many of the remaining functions in this section refer to the input and output queues of a terminal device. These queues implement a form of buffering Bwithin the kernel@ independent of the buffering implemented by I/O streams (see section ‰ŠP�”›Input/Output on Streams@�”˜).
‰IDX1120Š‰IDX1121Š@�”˜The Bterminal input queue@ is also sometimes referred to as its Btypeahead buffer@. It holds the characters that have been received from the terminal but not yet read by any process.
The size of the terminal's input queue is described by the HMAX_INPUT@ and H_POSIX_MAX_INPUT@ parameters; see section ‰ŠP�”›Limits on File System Capacity@�”˜. You are guaranteed a queue size of at least HMAX_INPUT@, but the queue might be larger, and might even dynamically change size. If input flow control is enabled by setting the HIXOFF@ input mode bit (see section ‰ŠP�”›Input Modes@�”˜), the terminal driver transmits STOP and START characters to the terminal when necessary to prevent the queue from overflowing. Otherwise, input may be lost if it comes in too fast from the terminal. In canonical mode, all input stays in the queue until a newline character is received, so the terminal input queue can fill up when you type a very long line. See section ‰ŠP�”›Two Styles of Input: Canonical or Not@�”˜.
‰IDX1122Š@�”˜The Bterminal output queue@ is like the input queue, but for output; it contains characters that have been written by processes, but not yet transmitted to the terminal. If output flow control is enabled by setting the HIXON@ input mode bit (see section ‰ŠP�”›Input Modes@�”˜), the terminal driver obeys STOP and STOP characters sent by the terminal to stop and restart transmission of output.
BClearing@ the terminal input queue means discarding any characters that have been received but not yet read. Similarly, clearing the terminal output queue means discarding any characters that have been written but not yet transmitted.
ˆ‰SEC235Št�”›Two Styles of Input: Canonical or Not

@�”˜POSIX systems support two basic modes of input: canonical and noncanonical.
‰IDX1123Š@�”˜In Bcanonical input processing@ mode, terminal input is processed in lines terminated by newline (H'\n'@), EOF, or EOL characters. No input can be read until an entire line has been typed by the user, and the Hread@ function (see section ‰ŠP�”›Input and Output Primitives@�”˜) returns at most a single line of input, no matter how many bytes are requested.
In canonical input mode, the operating system provides input editing facilities: some characters are interpreted specially to perform editing operations within the current line of text, such as ERASE and KILL. See section ‰ŠP�”›Characters for Input Editing@�”˜.
The constants H_POSIX_MAX_CANON@ and HMAX_CANON@ parameterize the maximum number of bytes which may appear in a single line of canonical input. See section ‰ŠP�”›Limits on File System Capacity@�”˜. You are guaranteed a maximum line length of at least HMAX_CANON@ bytes, but the maximum might be larger, and might even dynamically change size.
‰IDX1124Š@�”˜In Bnoncanonical input processing@ mode, characters are not grouped into lines, and ERASE and KILL processing is not performed. The granularity with which bytes are read in noncanonical input mode is controlled by the MIN and TIME settings. See section ‰ŠP�”›Noncanonical Input@�”˜.
Most programs use canonical input mode, because this gives the user a way to edit input line by line. The usual reason to use noncanonical mode is when the program accepts single-character commands or provides its own editing facilities.
The choice of canonical or noncanonical input is controlled by the HICANON@ flag in the Hc_lflag@ member of Hstruct termios@. See section ‰ŠP�”›Local Modes@�”˜.
ˆ‰SEC236Št�”›Terminal Modes

‰IDX1125Š@�”˜This section describes the various terminal attributes that control how input and output are done. The functions, data structures, and symbolic constants are all declared in the header file H`termios.h'@.
ˆ‰SEC237ŠT�”›Terminal Mode Data Types

‰IDX1126Š
@�”˜The entire collection of attributes of a terminal is stored in a structure of type Hstruct termios@. This structure is used with the functions Htcgetattr@ and Htcsetattr@ to read and set the attributes.

AData Type:@ Dstruct termios
Â‰IDX1127Š@�”˜Structure that records all the I/O attributes of a terminal. The structure includes at least the following members:
Htcflag_t c_iflag
Ä@A bit mask specifying flags for input modes; see section ‰ŠP�”›Input Modes@�”˜.
ÂHtcflag_t c_oflag
Ä@A bit mask specifying flags for output modes; see section ‰ŠP�”›Output Modes@�”˜.
ÂHtcflag_t c_cflag
Ä@A bit mask specifying flags for control modes; see section ‰ŠP�”›Control Modes@�”˜.
ÂHtcflag_t c_lflag
Ä@A bit mask specifying flags for local modes; see section ‰ŠP�”›Local Modes@�”˜.
ÂHcc_t c_cc[NCCS]
Ä@An array specifying which characters are associated with various control functions; see section ‰ŠP�”›Special Characters@�”˜.Â

The Hstruct termios@ structure also contains members which encode input and output transmission speeds, but the representation is not specified. See section ‰ŠP�”›Line Speed@�”˜, for how to examine and store the speed values.À

The following sections describe the details of the members of the Hstruct termios@ structure.

AData Type:@ Dtcflag_t
Â‰IDX1128Š@�”˜This is an unsigned integer type used to represent the various bit masks for terminal flags.À

AData Type:@ Dcc_t
Â‰IDX1129Š@�”˜This is an unsigned integer type used to represent characters associated with various terminal control functions.À

AMacro:@ int DNCCS
Â‰IDX1130Š@�”˜The value of this macro is the number of elements in the Hc_cc@ array.À

ˆ‰SEC238ŠT�”›Terminal Mode Functions

‰IDX1131Š

A�”˜Function:@ int Dtcgetattr@ B(int Bfiledes@, struct termios *Btermios-p@)
Â‰IDX1132Š@�”˜This function is used to examine the attributes of the terminal device with file descriptor Bfiledes@. The attributes are returned in the structure that Btermios-p@ points to.
If successful, Htcgetattr@ returns H0@. A return value of H-1@ indicates an error. The following Herrno@ error conditions are defined for this function:
HEBADF
Ä@The Bfiledes@ argument is not a valid file descriptor.
ÂHENOTTY
Ä@The Bfiledes@ is not associated with a terminal.Â
À

AFunction:@ int Dtcsetattr@ B(int Bfiledes@, int Bwhen@, const struct termios *Btermios-p@)
Â‰IDX1133Š@�”˜This function sets the attributes of the terminal device with file descriptor Bfiledes@. The new attributes are taken from the structure that Btermios-p@ points to.
The Bwhen@ argument specifies how to deal with input and output already queued. It can be one of the following values:
HTCSANOW
Ä‰IDX1134Š@�”˜Make the change immediately.
ÂHTCSADRAIN
Ä‰IDX1135Š@�”˜Make the change after waiting until all queued output has been written. You should usually use this option when changing parameters that affect output.
ÂHTCSAFLUSH
Ä‰IDX1136Š@�”˜This is like HTCSADRAIN@, but also discards any queued input.
ÂHTCSASOFT
Ä‰IDX1137Š@�”˜This is a flag bit that you can add to any of the above alternatives. Its meaning is to inhibit alteration of the state of the terminal hardware. It is a BSD extension; it is only supported on BSD systems and the GNU system. Using HTCSASOFT@ is exactly the same as setting the HCIGNORE@ bit in the Hc_cflag@ member of the structure Btermios-p@ points to. See section ‰ŠP�”›Control Modes@�”˜, for a description of HCIGNORE@.Â

If this function is called from a background process on its controlling terminal, normally all processes in the process group are sent a HSIGTTOU@ signal, in the same way as if the process were trying to write to the terminal. The exception is if the calling process itself is ignoring or blocking HSIGTTOU@ signals, in which case the operation is performed and no signal is sent. See section ‰ŠP�”›Job Control@�”˜.
If successful, Htcsetattr@ returns H0@. A return value of H-1@ indicates an error. The following Herrno@ error conditions are defined for this function:
HEBADF
Ä@The Bfiledes@ argument is not a valid file descriptor.
ÂHENOTTY
Ä@The Bfiledes@ is not associated with a terminal.
ÂHEINVAL
Ä@Either the value of the Hwhen@ argument is not valid, or there is something wrong with the data in the Btermios-p@ argument.Â
À

Although Htcgetattr@ and Htcsetattr@ specify the terminal device with a file descriptor, the attributes are those of the terminal device itself and not of the file descriptor. This means that the effects of changing terminal attributes are persistent; if another process opens the terminal file later on, it will see the changed attributes even though it doesn't have anything to do with the open file descriptor you originally specified in changing the attributes.
Similarly, if a single process has multiple or duplicated file descriptors for the same terminal device, changing the terminal attributes affects input and output to all of these file descriptors. This means, for example, that you can't open one file descriptor or stream to read from a terminal in the normal line-buffered, echoed mode; and simultaneously have another file descriptor for the same terminal that you use to read from it in single-character, non-echoed mode. Instead, you have to explicitly switch the terminal back and forth between the two modes.
ˆ‰SEC239ŠT�”›Setting Terminal Modes Properly

@�”˜When you set terminal modes, you should call Htcgetattr@ first to get the current modes of the particular terminal device, modify only those modes that you are really interested in, and store the result with Htcsetattr@.
It's a bad idea to simply initialize a Hstruct termios@ structure to a chosen set of attributes and pass it directly to Htcsetattr@. Your program may be run years from now, on systems that support members not documented in this manual. The way to avoid setting these members to unreasonable values is to avoid changing them.
What's more, different terminal devices may require different mode settings in order to function properly. So you should avoid blindly copying attributes from one terminal device to another.
When a member contains a collection of independent flags, as the Hc_iflag@, Hc_oflag@ and Hc_cflag@ members do, even setting the entire member is a bad idea, because particular operating systems have their own flags. Instead, you should start with the current value of the member and alter only the flags whose values matter in your program, leaving any other flags unchanged.
Here is an example of how to set one flag (HISTRIP@) in the Hstruct termios@ structure while properly preserving all the other data in the structure: int
set_istrip (int desc, int value)
{
struct termios settings;
int result;

result = tcgetattr (desc, &settings);
if (result < 0)
{
perror ("error in tcgetattr");
return 0;
}
settings.c_iflag &= ~ISTRIP;
if (value)
settings.c_iflag |= ISTRIP;
result = tcsetattr (desc, TCSANOW, &settings);
if (result < 0)
{
perror ("error in tcgetattr");
return;
}
return 1;
}
ˆ‰SEC240ŠT�”›Input Modes

@�”˜This section describes the terminal attribute flags that control fairly low-level aspects of input processing: handling of parity errors, break signals, flow control, and HRET@ and HLFD@ characters.
All of these flags are bits in the Hc_iflag@ member of the Hstruct termios@ structure. The member is an integer, and you change flags using the operators H&@, H|@ and H^@. Don't try to specify the entire value for Hc_iflag@---instead, change only specific flags and leave the rest untouched (see section ‰ŠP�”›Setting Terminal Modes Properly@�”˜).

AMacro:@ tcflag_t DINPCK
Â‰IDX1138Š‰IDX1139Š@�”˜If this bit is set, input parity checking is enabled. If it is not set, no checking at all is done for parity errors on input; the characters are simply passed through to the application.
Parity checking on input processing is independent of whether parity detection and generation on the underlying terminal hardware is enabled; see section ‰ŠP�”›Control Modes@�”˜. For example, you could clear the HINPCK@ input mode flag and set the HPARENB@ control mode flag to ignore parity errors on input, but still generate parity on output.
If this bit is set, what happens when a parity error is detected depends on whether the HIGNPAR@ or HPARMRK@ bits are set. If neither of these bits are set, a byte with a parity error is passed to the application as a H'\0'@ character.À

AMacro:@ tcflag_t DIGNPAR
Â‰IDX1140Š@�”˜If this bit is set, any byte with a framing or parity error is ignored. This is only useful if HINPCK@ is also set.À

AMacro:@ tcflag_t DPARMRK
Â‰IDX1141Š@�”˜If this bit is set, input bytes with parity or framing errors are marked when passed to the program. This bit is meaningful only when HINPCK@ is set and HIGNPAR@ is not set.
The way erroneous bytes are marked is with two preceding bytes, H377@ and H0@. Thus, the program actually reads three bytes for one erroneous byte received from the terminal.
If a valid byte has the value H0377@, and HISTRIP@ (see below) is not set, the program might confuse it with the prefix that marks a parity error. So a valid byte H0377@ is passed to the program as two bytes, H0377@ H0377@, in this case.À

AMacro:@ tcflag_t DISTRIP
Â‰IDX1142Š@�”˜If this bit is set, valid input bytes are stripped to seven bits; otherwise, all eight bits are available for programs to read.À

AMacro:@ tcflag_t DIGNBRK
Â‰IDX1143Š@�”˜If this bit is set, break conditions are ignored.
‰IDX1144Š@�”˜A Bbreak condition@ is defined in the context of asynchronous serial data transmission as a series of zero-value bits longer than a single byte.À

AMacro:@ tcflag_t DBRKINT
Â‰IDX1145Š@�”˜If this bit is set and HIGNBRK@ is not set, a break condition clears the terminal input and output queues and raises a HSIGINT@ signal for the foreground process group associated with the terminal.
If neither HBRKINT@ nor HIGNBRK@ are set, a break condition is passed to the application as a single H'\0'@ character if HPARMRK@ is not set, or otherwise as a three-character sequence H'\377'@, H'\0'@, H'\0'@.À

AMacro:@ tcflag_t DIGNCR
Â‰IDX1146Š@�”˜If this bit is set, carriage return characters (H'\r'@) are discarded on input. Discarding carriage return may be useful on terminals that send both carriage return and linefeed when you type the HRET@ key.À

AMacro:@ tcflag_t DICRNL
Â‰IDX1147Š@�”˜If this bit is set and HIGNCR@ is not set, carriage return characters (H'\r'@) received as input are passed to the application as newline characters (H'\n'@).À

AMacro:@ tcflag_t DINLCR
Â‰IDX1148Š@�”˜If this bit is set, newline characters (H'\n'@) received as input are passed to the application as carriage return characters (H'\r'@).À

AMacro:@ tcflag_t DIXOFF
Â‰IDX1149Š@�”˜If this bit is set, start/stop control on input is enabled. In other words, the computer sends STOP and START characters as necessary to prevent input from coming in faster than programs are reading it. The idea is that the actual terminal hardware that is generating the input data responds to a STOP character by suspending transmission, and to a START character by resuming transmission. See section ‰ŠP�”›Special Characters for Flow Control@�”˜.À

AMacro:@ tcflag_t DIXON
Â‰IDX1150Š@�”˜If this bit is set, start/stop control on output is enabled. In other words, if the computer receives a STOP character, it suspends output until a START character is received. In this case, the STOP and START characters are never passed to the application program. If this bit is not set, then START and STOP can be read as ordinary characters. See section ‰ŠP�”›Special Characters for Flow Control@�”˜.À

AMacro:@ tcflag_t DIXANY
Â‰IDX1151Š@�”˜If this bit is set, any input character restarts output when output has been suspended with the STOP character. Otherwise, only the START character restarts output.
This is a BSD extension; it exists only on BSD systems and the GNU system.À

AMacro:@ tcflag_t DIMAXBEL
Â‰IDX1152Š@�”˜If this bit is set, then filling up the terminal input buffer sends a BEL character (code H007@) to the terminal to ring the bell.
This is a BSD extension.À

ˆ‰SEC241ŠT�”›Output Modes

@�”˜This section describes the terminal flags and fields that control how output characters are translated and padded for display. All of these are contained in the Hc_oflag@ member of the Hstruct termios@ structure.
The Hc_oflag@ member itself is an integer, and you change the flags and fields using the operators H&@, H|@, and H^@. Don't try to specify the entire value for Hc_oflag@---instead, change only specific flags and leave the rest untouched (see section ‰ŠP�”›Setting Terminal Modes Properly@�”˜).

AMacro:@ tcflag_t DOPOST
Â‰IDX1153Š@�”˜If this bit is set, output data is processed in some unspecified way so that it is displayed appropriately on the terminal device. This typically includes mapping newline characters (H'\n'@) onto carriage return and linefeed pairs.
If this bit isn't set, the characters are transmitted as-is.À

The following three bits are BSD features, and they exist only BSD systems and the GNU system. They are effective only if HOPOST@ is set.

AMacro:@ tcflag_t DONLCR
Â‰IDX1154Š@�”˜If this bit is set, convert the newline character on output into a pair of characters, carriage return followed by linefeed.À

AMacro:@ tcflag_t DOXTABS
Â‰IDX1155Š@�”˜If this bit is set, convert tab characters on output into the appropriate number of spaces to emulate a tab stop every eight columns.À

AMacro:@ tcflag_t DONOEOT
Â‰IDX1156Š@�”˜If this bit is set, discard HC-d@ characters (code H004@) on output. These characters cause many dial-up terminals to disconnect.À

ˆ‰SEC242ŠT�”›Control Modes

@�”˜This section describes the terminal flags and fields that control parameters usually associated with asynchronous serial data transmission. These flags may not make sense for other kinds of terminal ports (such as a network connection pseudo-terminal). All of these are contained in the Hc_cflag@ member of the Hstruct termios@ structure.
The Hc_cflag@ member itself is an integer, and you change the flags and fields using the operators H&@, H|@, and H^@. Don't try to specify the entire value for Hc_cflag@---instead, change only specific flags and leave the rest untouched (see section ‰ŠP�”›Setting Terminal Modes Properly@�”˜).

AMacro:@ tcflag_t DCLOCAL
Â‰IDX1157Š@�”˜If this bit is set, it indicates that the terminal is connected "locally" and that the modem status lines (such as carrier detect) should be ignored. ‰IDX1158Š‰IDX1159Š
@�”˜On many systems if this bit is not set and you call Hopen@ without the HO_NONBLOCK@ flag set, Hopen@ blocks until a modem connection is established.
If this bit is not set and a modem disconnect is detected, a HSIGHUP@ signal is sent to the controlling process group for the terminal (if it has one). Normally, this causes the process to exit; see section ‰ŠP�”›Signal Handling@�”˜. Reading from the terminal after a disconnect causes an end-of-file condition, and writing causes an HEIO@ error to be returned. The terminal device must be closed and reopened to clear the condition. ‰IDX1160ŠÀ

A�”˜Macro:@ tcflag_t DHUPCL
Â‰IDX1161Š@�”˜If this bit is set, a modem disconnect is generated when all processes that have the terminal device open have either closed the file or exited.À

AMacro:@ tcflag_t DCREAD
Â‰IDX1162Š@�”˜If this bit is set, input can be read from the terminal. Otherwise, input is discarded when it arrives.À

AMacro:@ tcflag_t DCSTOPB
Â‰IDX1163Š@�”˜If this bit is set, two stop bits are used. Otherwise, only one stop bit is used.À

AMacro:@ tcflag_t DPARENB
Â‰IDX1164Š@�”˜If this bit is set, generation and detection of a parity bit are enabled. See section ‰ŠP�”›Input Modes@�”˜, for information on how input parity errors are handled.
If this bit is not set, no parity bit is added to output characters, and input characters are not checked for correct parity.À

AMacro:@ tcflag_t DPARODD
Â‰IDX1165Š@�”˜This bit is only useful if HPARENB@ is set. If HPARODD@ is set, odd parity is used, otherwise even parity is used.À

The control mode flags also includes a field for the number of bits per character. You can use the HCSIZE@ macro as a mask to extract the value, like this: Hsettings.c_cflag & CSIZE@.

AMacro:@ tcflag_t DCSIZE
Â‰IDX1166Š@�”˜This is a mask for the number of bits per character.À

AMacro:@ tcflag_t DCS5
Â‰IDX1167Š@�”˜This specifies five bits per byte.À

AMacro:@ tcflag_t DCS6
Â‰IDX1168Š@�”˜This specifies six bits per byte.À

AMacro:@ tcflag_t DCS7
Â‰IDX1169Š@�”˜This specifies seven bits per byte.À

AMacro:@ tcflag_t DCS8
Â‰IDX1170Š@�”˜This specifies eight bits per byte.À

The following four bits are BSD extensions; this exist only on BSD systems and the GNU system.

AMacro:@ tcflag_t DCCTS_OFLOW
Â‰IDX1171Š@�”˜If this bit is set, enable flow control of output based on the CTS wire (RS232 protocol).À

AMacro:@ tcflag_t DCRTS_IFLOW
Â‰IDX1172Š@�”˜If this bit is set, enable flow control of input based on the RTS wire (RS232 protocol).À

AMacro:@ tcflag_t DMDMBUF
Â‰IDX1173Š@�”˜If this bit is set, enable carrier-based flow control of output.À

AMacro:@ tcflag_t DCIGNORE
Â‰IDX1174Š@�”˜If this bit is set, it says to ignore the control modes and line speed values entirely. This is only meaningful in a call to Htcsetattr@.
The Hc_cflag@ member and the line speed values returned by Hcfgetispeed@ and Hcfgetospeed@ will be unaffected by the call. HCIGNORE@ is useful if you want to set all the software modes in the other members, but leave the hardware details in Hc_cflag@ unchanged. (This is how the HTCSASOFT@ flag to Htcsettattr@ works.)
This bit is never set in the structure filled in by Htcgetattr@.À

ˆ‰SEC243ŠT�”›Local Modes

@�”˜This section describes the flags for the Hc_lflag@ member of the Hstruct termios@ structure. These flags generally control higher-level aspects of input processing than the input modes flags described in section ‰ŠP�”›Input Modes@�”˜, such as echoing, signals, and the choice of canonical or noncanonical input.
The Hc_lflag@ member itself is an integer, and you change the flags and fields using the operators H&@, H|@, and H^@. Don't try to specify the entire value for Hc_lflag@---instead, change only specific flags and leave the rest untouched (see section ‰ŠP�”›Setting Terminal Modes Properly@�”˜).

AMacro:@ tcflag_t DICANON
Â‰IDX1175Š@�”˜This bit, if set, enables canonical input processing mode. Otherwise, input is processed in noncanonical mode. See section ‰ŠP�”›Two Styles of Input: Canonical or Not@�”˜.À

AMacro:@ tcflag_t DECHO
Â‰IDX1176Š@�”˜If this bit is set, echoing of input characters back to the terminal is enabled. ‰IDX1177ŠÀ

A�”˜Macro:@ tcflag_t DECHOE
Â‰IDX1178Š@�”˜If this bit is set, echoing indicates erasure of input with the ERASE character by erasing the last character in the current line from the screen. Otherwise, the character erased is re-echoed to show what has happened (suitable for a printing terminal).
This bit only controls the display behavior; the HICANON@ bit by itself controls actual recognition of the ERASE character and erasure of input, without which HECHOE@ is simply irrelevant.À

AMacro:@ tcflag_t DECHOPRT
Â‰IDX1179Š@�”˜This bit is like HECHOE@, enables display of the ERASE character in a way that is geared to a hardcopy terminal. When you type the ERASE character, a H`\'@ character is printed followed by the first character erased. Typing the ERASE character again just prints the next character erased. Then, the next time you type a normal character, a H`/'@ character is printed before the character echoes.
This is a BSD extension, and exists only in BSD systems and the GNU system.À

AMacro:@ tcflag_t DECHOK
Â‰IDX1180Š@�”˜This bit enables special display of the KILL character by moving to a new line after echoing the KILL character normally. The behavior of HECHOKE@ (below) is nicer to look at.
If this bit is not set, the KILL character echoes just as it would if it were not the KILL character. Then it is up to the user to remember that the KILL character has erased the preceding input; there is no indication of this on the screen.
This bit only controls the display behavior; the HICANON@ bit by itself controls actual recognition of the KILL character and erasure of input, without which HECHOK@ is simply irrelevant.À

AMacro:@ tcflag_t DECHOKE
Â‰IDX1181Š@�”˜This bit is similar to HECHOK@. It enables special display of the KILL character by erasing on the screen the entire line that has been killed. This is a BSD extension, and exists only in BSD systems and the GNU system.À

AMacro:@ tcflag_t DECHONL
Â‰IDX1182Š@�”˜If this bit is set and the HICANON@ bit is also set, then the newline (H'\n'@) character is echoed even if the HECHO@ bit is not set.À

AMacro:@ tcflag_t DECHOCTL
Â‰IDX1183Š@�”˜If this bit is set and the HECHO@ bit is also set, echo control characters with H`^'@ followed by the corresponding text character. Thus, control-A echoes as H`^A'@. This is usually the preferred mode for interactive input, because echoing a control character back to the terminal could have some undesired effect on the terminal.
This is a BSD extension, and exists only in BSD systems and the GNU system.À

AMacro:@ tcflag_t DISIG
Â‰IDX1184Š@�”˜This bit controls whether the INTR, QUIT, and SUSP characters are recognized. The functions associated with these characters are performed if and only if this bit is set. Being in canonical or noncanonical input mode has no affect on the interpretation of these characters.
You should use caution when disabling recognition of these characters. Programs that cannot be interrupted interactively are very user-unfriendly. If you clear this bit, your program should provide some alternate interface that allows the user to interactively send the signals associated with these characters, or to escape from the program. ‰IDX1185Š
@�”˜See section ‰ŠP�”›Characters that Cause Signals@�”˜.À

AMacro:@ tcflag_t DIEXTEN
Â‰IDX1186Š@�”˜POSIX.1 gives HIEXTEN@ implementation-defined meaning, so you cannot rely on this interpretation on all systems.
On BSD systems and the GNU system, it enables the LNEXT and DISCARD characters. See section ‰ŠP�”›Other Special Characters@�”˜.À

AMacro:@ tcflag_t DNOFLSH
Â‰IDX1187Š@�”˜Normally, the INTR, QUIT, and SUSP characters cause input and output queues for the terminal to be cleared. If this bit is set, the queues are not cleared.À

AMacro:@ tcflag_t DTOSTOP
Â‰IDX1188Š@�”˜If this bit is set and the system supports job control, then HSIGTTOU@ signals are generated by background processes that attempt to write to the terminal. See section ‰ŠP�”›Access to the Controlling Terminal@�”˜.À

The following bits are BSD extensions; they exist only in BSD systems and the GNU system.

AMacro:@ tcflag_t DALTWERASE
Â‰IDX1189Š@�”˜This bit determines how far the WERASE character should erase. The WERASE character erases back to the beginning of a word; the question is, where do words begin?
If this bit is clear, then the beginning of a word is a nonwhitespace character following a whitespace character. If the bit is set, then the beginning of a word is an alphanumeric character or underscore following a character which is none of those.
See section ‰ŠP�”›Characters for Input Editing@�”˜, for more information about the WERASE character.À

AMacro:@ tcflag_t DFLUSHO
Â‰IDX1190Š@�”˜This is the bit that toggles when the user types the DISCARD character. While this bit is set, all output is discarded. See section ‰ŠP�”›Other Special Characters@�”˜.À

AMacro:@ tcflag_t DNOKERNINFO
Â‰IDX1191Š@�”˜Setting this bit disables handling of the STATUS character. See section ‰ŠP�”›Other Special Characters@�”˜.À

AMacro:@ tcflag_t DPENDIN
Â‰IDX1192Š@�”˜If this bit is set, it indicates that there is a line of input that needs to be reprinted. Typing the REPRINT character sets this bit; the bit remains set until reprinting is finished. See section ‰ŠP�”›Characters for Input Editing@�”˜.À

ˆ‰SEC244ŠT�”›Line Speed

‰IDX1193Š‰IDX1194Š‰IDX1195Š‰IDX1196Š
@�”˜The terminal line speed tells the computer how fast to read and write data on the terminal.
If the terminal is connected to a real serial line, the terminal speed you specify actually controls the line--if it doesn't match the terminal's own idea of the speed, communication does not work. Real serial ports accept only certain standard speeds. Also, particular hardware may not support even all the standard speeds. Specifying a speed of zero hangs up a dialup connection and turns off modem control signals.
If the terminal is not a real serial line (for example, if it is a network connection), then the line speed won't really affect data transmission speed, but some programs will use it to determine the amount of padding needed. It's best to specify a line speed value that matches the actual speed of the actual terminal, but you can safely experiment with different values to vary the amount of padding.
There are actually two line speeds for each terminal, one for input and one for output. You can set them independently, but most often terminals use the same speed for both directions.
The speed values are stored in the Hstruct termios@ structure, but don't try to access them in the Hstruct termios@ structure directly. Instead, you should use the following functions to read and store them:

AFunction:@ speed_t Dcfgetospeed@ B(const struct termios *Btermios-p@)
Â‰IDX1197Š@�”˜This function returns the output line speed stored in the structure H*Jtermios-p@.À

AFunction:@ speed_t Dcfgetispeed@ B(const struct termios *Btermios-p@)
Â‰IDX1198Š@�”˜This function returns the input line speed stored in the structure H*Jtermios-p@.À

AFunction:@ int Dcfsetospeed@ B(struct termios *Btermios-p@, speed_t Bspeed@)
Â‰IDX1199Š@�”˜This function stores Bspeed@ in H*Jtermios-p@ as the output speed. The normal return value is H0@; a value of H-1@ indicates an error. If Bspeed@ is not a speed, Hcfsetospeed@ returns H-1@.À

AFunction:@ int Dcfsetispeed@ B(struct termios *Btermios-p@, speed_t Bspeed@)
Â‰IDX1200Š@�”˜This function stores Bspeed@ in H*Jtermios-p@ as the input speed. The normal return value is H0@; a value of H-1@ indicates an error. If Bspeed@ is not a speed, Hcfsetospeed@ returns H-1@.À

AFunction:@ int Dcfsetspeed@ B(struct termios *Btermios-p@, speed_t Bspeed@)
Â‰IDX1201Š@�”˜This function stores Bspeed@ in H*Jtermios-p@ as both the input and output speeds. The normal return value is H0@; a value of H-1@ indicates an error. If Bspeed@ is not a speed, Hcfsetspeed@ returns H-1@. This function is an extension in 4.4 BSD.À

AData Type:@ Dspeed_t
Â‰IDX1202Š@�”˜The Hspeed_t@ type is an unsigned integer data type used to represent line speeds.À

The functions Hcfsetospeed@ and Hcfsetispeed@ report errors only for speed values that the system simply cannot handle. If you specify a speed value that is basically acceptable, then those functions will succeed. But they do not check that a particular hardware device can actually support the specified speeds--in fact, they don't know which device you plan to set the speed for. If you use Htcsetattr@ to set the speed of a particular device to a value that it cannot handle, Htcsetattr@ returns H-1@.
DPortability note:@ In the GNU library, the functions above accept speeds measured in bits per second as input, and return speed values measured in bits per second. Other libraries require speeds to be indicated by special codes. For POSIX.1 portability, you must use one of the following symbols to represent the speed; their precise numeric values are system-dependent, but each name has a fixed meaning: HB110@ stands for 110 bps, HB300@ for 300 bps, and so on. There is no portable way to represent any speed but these, but these are the only speeds that typical serial lines can support.
‰IDX1203Š‰IDX1204Š‰IDX1205Š‰IDX1206Š‰IDX1207Š‰IDX1208Š‰IDX1209Š‰IDX1210Š‰IDX1211Š‰IDX1212Š‰IDX1213Š‰IDX1214Š‰IDX1215Š‰IDX1216Š‰IDX1217Š‰IDX1218Š@�”˜B0 B50 B75 B110 B134 B150 B200
B300 B600 B1200 B1800 B2400 B4800
B9600 B19200 B38400
‰IDX1219Š‰IDX1220Š@�”˜BSD defines two additional speed symbols as aliases: HEXTA@ is an alias for HB19200@ and HEXTB@ is an alias for HB38400@. These aliases are obsolete.
ˆ‰SEC245ŠT�”›Special Characters

@�”˜In canonical input, the terminal driver recognizes a number of special characters which perform various control functions. These include the ERASE character (usually HDEL@) for editing input, and other editing characters. The INTR character (normally HC-c@) for sending a HSIGINT@ signal, and other signal-raising characters, may be available in either canonical or noncanonical input mode. All these characters are described in this section.
The particular characters used are specified in the Hc_cc@ member of the Hstruct termios@ structure. This member is an array; each element specifies the character for a particular role. Each element has a symbolic constant that stands for the index of that element--for example, HINTR@ is the index of the element that specifies the INTR character, so storing H'='@ in JtermiosH.c_cc[INTR]@ specifies H`='@ as the INTR character.
‰IDX1221Š@�”˜On some systems, you can disable a particular special character function by specifying the value H_POSIX_VDISABLE@ for that role. This value is unequal to any possible character code. See section ‰ŠP�”›Optional Features in File Support@�”˜, for more information about how to tell whether the operating system you are using supports H_POSIX_VDISABLE@.
ˆ‰SEC246ŠT�”›Characters for Input Editing

@�”˜These special characters are active only in canonical input mode. See section ‰ŠP�”›Two Styles of Input: Canonical or Not@�”˜.

AMacro:@ int DVEOF
Â‰IDX1222Š‰IDX1223Š@�”˜This is the subscript for the EOF character in the special control character array. JtermiosH.c_cc[VEOF]@ holds the character itself.
The EOF character is recognized only in canonical input mode. It acts as a line terminator in the same way as a newline character, but if the EOF character is typed at the beginning of a line it causes Hread@ to return a byte count of zero, indicating end-of-file. The EOF character itself is discarded.
Usually, the EOF character is HC-d@.À

AMacro:@ int DVEOL
Â‰IDX1224Š‰IDX1225Š@�”˜This is the subscript for the EOL character in the special control character array. JtermiosH.c_cc[VEOL]@ holds the character itself.
The EOL character is recognized only in canonical input mode. It acts as a line terminator, just like a newline character. The EOL character is not discarded; it is read as the last character in the input line.
You don't need to use the EOL character to make HRET@ end a line. Just set the ICRNL flag. In fact, this is the default state of affairs.À

AMacro:@ int DVEOL2
Â‰IDX1226Š‰IDX1227Š@�”˜This is the subscript for the EOL2 character in the special control character array. JtermiosH.c_cc[VEOL2]@ holds the character itself.
The EOL2 character works just like the EOL character (see above), but it can be a different character. Thus, you can specify two characters to terminate an input line, by setting EOL to one of them and EOL2 to the other.
The EOL2 character is a BSD extension; it exists only on BSD systems and the GNU system.À

AMacro:@ int DVERASE
Â‰IDX1228Š‰IDX1229Š@�”˜This is the subscript for the ERASE character in the special control character array. JtermiosH.c_cc[VERASE]@ holds the character itself.
The ERASE character is recognized only in canonical input mode. When the user types the erase character, the previous character typed is discarded. (If the terminal generates multibyte character sequences, this may cause more than one byte of input to be discarded.) This cannot be used to erase past the beginning of the current line of text. The ERASE character itself is discarded.
Usually, the ERASE character is HDEL@.À

AMacro:@ int DVWERASE
Â‰IDX1230Š‰IDX1231Š@�”˜This is the subscript for the WERASE character in the special control character array. JtermiosH.c_cc[VWERASE]@ holds the character itself.
The WERASE character is recognized only in canonical mode. It erases an entire word of prior input, and any whitespace after it; whitespace characters before the word are not erased.
The definition of a "word" depends on the setting of the HALTWERASE@ mode; see section ‰ŠP�”›Local Modes@�”˜.
If the HALTWERASE@ mode is not set, a word is defined as a sequence of any characters except space or tab.
If the HALTWERASE@ mode is set, a word is defined as a sequence of characters containing only letters, numbers, and underscores, optionally followed by one character that is not a letter, number, or underscore.
The WERASE character is usually HC-w@.
This is a BSD extension.À

AMacro:@ int DVKILL
Â‰IDX1232Š‰IDX1233Š@�”˜This is the subscript for the KILL character in the special control character array. JtermiosH.c_cc[VKILL]@ holds the character itself.
The KILL character is recognized only in canonical input mode. When the user types the kill character, the entire contents of the current line of input are discarded. The kill character itself is discarded too.
The KILL character is usually HC-u@.À

AMacro:@ int DVREPRINT
Â‰IDX1234Š‰IDX1235Š@�”˜This is the subscript for the REPRINT character in the special control character array. JtermiosH.c_cc[VREPRINT]@ holds the character itself.
The REPRINT character is recognized only in canonical mode. It reprints the current input line. If some asynchronous output has come while you are typing, this lets you see the line you are typing clearly again.
The REPRINT character is usually HC-r@.
This is a BSD extension.À

ˆ‰SEC247ŠT�”›Characters that Cause Signals

@�”˜These special characters may be active in either canonical or noncanonical input mode, but only when the HISIG@ flag is set (see section ‰ŠP�”›Local Modes@�”˜).

AMacro:@ int DVINTR
Â‰IDX1236Š‰IDX1237Š‰IDX1238Š@�”˜This is the subscript for the INTR character in the special control character array. JtermiosH.c_cc[VINTR]@ holds the character itself.
The INTR (interrupt) character raises a HSIGINT@ signal for all processes in the foreground job associated with the terminal. The INTR character itself is then discarded. See section ‰ŠP�”›Signal Handling@�”˜, for more information about signals.
Typically, the INTR character is HC-c@.À

AMacro:@ int DVQUIT
Â‰IDX1239Š‰IDX1240Š@�”˜This is the subscript for the QUIT character in the special control character array. JtermiosH.c_cc[VQUIT]@ holds the character itself.
The QUIT character raises a HSIGQUIT@ signal for all processes in the foreground job associated with the terminal. The QUIT character itself is then discarded. See section ‰ŠP�”›Signal Handling@�”˜, for more information about signals.
Typically, the QUIT character is HC-\@.À

AMacro:@ int DVSUSP
Â‰IDX1241Š‰IDX1242Š‰IDX1243Š@�”˜This is the subscript for the SUSP character in the special control character array. JtermiosH.c_cc[VSUSP]@ holds the character itself.
The SUSP (suspend) character is recognized only if the implementation supports job control (see section ‰ŠP�”›Job Control@�”˜). It causes a HSIGTSTP@ signal to be sent to all processes in the foreground job associated with the terminal. The SUSP character itself is then discarded. See section ‰ŠP�”›Signal Handling@�”˜, for more information about signals.
Typically, the SUSP character is HC-z@.À

Few applications disable the normal interpretation of the SUSP character. If your program does this, it should provide some other mechanism for the user to stop the job. When the user invokes this mechanism, the program should send a HSIGTSTP@ signal to the process group of the process, not just to the process itself. See section ‰ŠP�”›Signaling Another Process@�”˜.

AMacro:@ int DVDSUSP
Â‰IDX1244Š‰IDX1245Š‰IDX1246Š@�”˜This is the subscript for the DSUSP character in the special control character array. JtermiosH.c_cc[VDSUSP]@ holds the character itself.
The DSUSP (suspend) character is recognized only if the implementation supports job control (see section ‰ŠP�”›Job Control@�”˜). It sends a HSIGTSTP@ signal, like the SUSP character, but not right away--only when the program tries to read it as input. Not all systems with job control support DSUSP; only BSD-compatible systems (including the GNU system).
See section ‰ŠP�”›Signal Handling@�”˜, for more information about signals.
Typically, the DSUSP character is HC-y@.À

ˆ‰SEC248ŠT�”›Special Characters for Flow Control

@�”˜These special characters may be active in either canonical or noncanonical input mode, but their use is controlled by the flags HIXON@ and HIXOFF@ (see section ‰ŠP�”›Input Modes@�”˜).

AMacro:@ int DVSTART
Â‰IDX1247Š‰IDX1248Š@�”˜This is the subscript for the START character in the special control character array. JtermiosH.c_cc[VSTART]@ holds the character itself.
The START character is used to support the HIXON@ and HIXOFF@ input modes. If HIXON@ is set, receiving a START character resumes suspended output; the START character itself is discarded. If HIXANY@ is set, receiving any character at all resumes suspended output; the resuming character is not discarded unless it is the START character. HIXOFF@ is set, the system may also transmit START characters to the terminal.
The usual value for the START character is HC-q@. You may not be able to change this value--the hardware may insist on using HC-q@ regardless of what you specify.À

AMacro:@ int DVSTOP
Â‰IDX1249Š‰IDX1250Š@�”˜This is the subscript for the STOP character in the special control character array. JtermiosH.c_cc[VSTOP]@ holds the character itself.
The STOP character is used to support the HIXON@ and HIXOFF@ input modes. If HIXON@ is set, receiving a STOP character causes output to be suspended; the STOP character itself is discarded. If HIXOFF@ is set, the system may also transmit STOP characters to the terminal, to prevent the input queue from overflowing.
The usual value for the STOP character is HC-s@. You may not be able to change this value--the hardware may insist on using HC-s@ regardless of what you specify.À

ˆ‰SEC249ŠT�”›Other Special Characters

@�”˜These special characters exist only in BSD systems and the GNU system.

AMacro:@ int DVLNEXT
Â‰IDX1251Š‰IDX1252Š@�”˜This is the subscript for the LNEXT character in the special control character array. JtermiosH.c_cc[VLNEXT]@ holds the character itself.
The LNEXT character is recognized only when HIEXTEN@ is set, but in both canonical and noncanonical mode. It disables any special significance of the next character the user types. Even if the character would normally perform some editing function or generate a signal, it is read as a plain character. This is the analogue of the HC-q@ command in Emacs. "LNEXT" stands for "literal next."
The LNEXT character is usually HC-v@.À

AMacro:@ int DVDISCARD
Â‰IDX1253Š‰IDX1254Š@�”˜This is the subscript for the DISCARD character in the special control character array. JtermiosH.c_cc[VDISCARD]@ holds the character itself.
The DISCARD character is recognized only when HIEXTEN@ is set, but in both canonical and noncanonical mode. Its effect is to toggle the discard-output flag. When this flag is set, all program output is discarded. Setting the flag also discards all output currently in the output buffer. Typing any other character resets the flag.À

AMacro:@ int DVSTATUS
Â‰IDX1255Š‰IDX1256Š@�”˜This is the subscript for the STATUS character in the special control character array. JtermiosH.c_cc[VSTATUS]@ holds the character itself.
The STATUS character's effect is to print out a status message about how the current process is running.
The STATUS character is recognized only in canonical mode, and only if HNOKERNINFO@ is not set.À

ˆ‰SEC250ŠT�”›Noncanonical Input

@�”˜In noncanonical input mode, the special editing characters such as ERASE and KILL are ignored. The system facilities for the user to edit input are disabled in noncanonical mode, so that all input characters (unless they are special for signal or flow-control purposes) are passed to the application program exactly as typed. It is up to the application program to give the user ways to edit the input, if appropriate.
Noncanonical mode offers special parameters called MIN and TIME for controlling whether and how long to wait for input to be available. You can even use them to avoid ever waiting--to return immediately with whatever input is available, or with no input.
The MIN and TIME are stored in elements of the Hc_cc@ array, which is a member of the Hstruct termios@ structure. Each element of this array has a particular role, and each element has a symbolic constant that stands for the index of that element. HVMIN@ and HVMAX@ are the names for the indices in the array of the MIN and TIME slots.

AMacro:@ int DVMIN
Â‰IDX1257Š‰IDX1258Š@�”˜This is the subscript for the MIN slot in the Hc_cc@ array. Thus, JtermiosH.c_cc[VMIN]@ is the value itself.
The MIN slot is only meaningful in noncanonical input mode; it specifies the minimum number of bytes that must be available in the input queue in order for Hread@ to return.À

AMacro:@ int DVTIME
Â‰IDX1259Š‰IDX1260Š@�”˜This is the subscript for the TIME slot in the Hc_cc@ array. Thus, JtermiosH.c_cc[VTIME]@ is the value itself.
The TIME slot is only meaningful in noncanonical input mode; it specifies how long to wait for input before returning, in units of 0.1 seconds.À

The MIN and TIME values interact to determine the criterion for when Hread@ should return; their precise meanings depend on which of them are nonzero. There are four possible cases: þÂ
• Both TIME and MIN are nonzero. In this case, TIME specifies how long to wait after each input character to see if more input arrives. After the first character received, Hread@ keeps waiting until either MIN bytes have arrived in all, or TIME elapses with no further input. Hread@ always blocks until the first character arrives, even if TIME elapses first. Hread@ can return more than MIN characters if more than MIN happen to be in the queue.
• Both MIN and TIME are zero. In this case, Hread@ always returns immediately with as many characters as are available in the queue, up to the number requested. If no input is immediately available, Hread@ returns a value of zero.
• MIN is zero but TIME has a nonzero value. In this case, Hread@ waits for time TIME for input to become available; the availability of a single byte is enough to satisfy the read request and cause Hread@ to return. When it returns, it returns as many characters as are available, up to the number requested. If no input is available before the timer expires, Hread@ returns a value of zero.
• TIME is zero but MIN has a nonzero value. In this case, Hread@ waits until at least MIN bytes are available in the queue. At that time, Hread@ returns as many characters as are available, up to the number requested. Hread@ can return more than MIN characters if more than MIN happen to be in the queue.Àð
What happens if MIN is 50 and you ask to read just 10 bytes? Normally, Hread@ waits until there are 50 bytes in the buffer (or, more generally, the wait condition described above is satisfied), and then reads 10 of them, leaving the other 40 buffered in the operating system for a subsequent call to Hread@.
DPortability note:@ On some systems, the MIN and TIME slots are actually the same as the EOF and EOL slots. This causes no serious problem because the MIN and TIME slots are used only in noncanonical input and the EOF and EOL slots are used only in canonical input, but it isn't very clean. The GNU library allocates separate slots for these uses.

AFunction:@ int Dcfmakeraw@ B(struct termios *Btermios-p@)
Â‰IDX1261Š@�”˜This function provides an easy way to set up H*Jtermios-p@ for what has traditionally been called "raw mode" in BSD. This uses noncanonical input, and turns off most processing to give an unmodified channel to the terminal.
It does exactly this: Btermios-p@->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
|INLCR|IGNCR|ICRNL|IXON);
Btermios-p@->c_oflag &= ~OPOST;
Btermios-p@->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
Btermios-p@->c_cflag &= ~(CSIZE|PARENB);
Btermios-p@->c_cflag |= CS8; À

ˆ‰SEC251Št�”›Line Control Functions

‰IDX1262Š
@�”˜These functions perform miscellaneous control actions on terminal devices. As regards terminal access, they are treated like doing output: if any of these functions is used by a background process on its controlling terminal, normally all processes in the process group are sent a HSIGTTOU@ signal. The exception is if the calling process itself is ignoring or blocking HSIGTTOU@ signals, in which case the operation is performed and no signal is sent. See section ‰ŠP�”›Job Control@�”˜.
‰IDX1263Š
A�”˜Function:@ int Dtcsendbreak@ B(int Bfiledes@, int Bduration@)
Â‰IDX1264Š@�”˜This function generates a break condition by transmitting a stream of zero bits on the terminal associated with the file descriptor Bfiledes@. The duration of the break is controlled by the Bduration@ argument. If zero, the duration is between 0.25 and 0.5 seconds. The meaning of a nonzero value depends on the operating system.
This function does nothing if the terminal is not an asynchronous serial data port.
The return value is normally zero. In the event of an error, a value of H-1@ is returned. The following Herrno@ error conditions are defined for this function:
HEBADF
Ä@The Bfiledes@ is not a valid file descriptor.
ÂHENOTTY
Ä@The Bfiledes@ is not associated with a terminal device.Â
À

‰IDX1265Š‰IDX1266Š
A�”˜Function:@ int Dtcdrain@ B(int Bfiledes@)
Â‰IDX1267Š@�”˜The Htcdrain@ function waits until all queued output to the terminal Bfiledes@ has been transmitted.
The return value is normally zero. In the event of an error, a value of H-1@ is returned. The following Herrno@ error conditions are defined for this function:
HEBADF
Ä@The Bfiledes@ is not a valid file descriptor.
ÂHENOTTY
Ä@The Bfiledes@ is not associated with a terminal device.
ÂHEINTR
Ä@The operation was interrupted by delivery of a signal. See section ‰ŠP�”›Primitives Interrupted by Signals@�”˜.Â
À

‰IDX1268Š‰IDX1269Š
A�”˜Function:@ int Dtcflush@ B(int Bfiledes@, int Bqueue@)
Â‰IDX1270Š@�”˜The Htcflush@ function is used to clear the input and/or output queues associated with the terminal file Bfiledes@. The Bqueue@ argument specifies which queue(s) to clear, and can be one of the following values:
HTCIFLUSH
Ä‰IDX1271Š@�”˜Clear any input data received, but not yet read. ‰IDX1272Š
ÂH�”˜TCOFLUSH
Ä@Clear any output data written, but not yet transmitted. ‰IDX1273Š
ÂH�”˜TCIOFLUSH
Ä@Clear both queued input and output.Â

The return value is normally zero. In the event of an error, a value of H-1@ is returned. The following Herrno@ error conditions are defined for this function:
HEBADF
Ä@The Bfiledes@ is not a valid file descriptor.
ÂHENOTTY
Ä@The Bfiledes@ is not associated with a terminal device.
ÂHEINVAL
Ä@A bad value was supplied as the Bqueue@ argument.Â

It is unfortunate that this function is named Htcflush@, because the term "flush" is normally used for quite another operation--waiting until all output is transmitted--and using it for discarding input or output would be confusing. Unfortunately, the name Htcflush@ comes from POSIX and we cannot change it.À

‰IDX1274Š‰IDX1275Š
A�”˜Function:@ int Dtcflow@ B(int Bfiledes@, int Baction@)
Â‰IDX1276Š@�”˜The Htcflow@ function is used to perform operations relating to XON/XOFF flow control on the terminal file specified by Bfiledes@.
The Baction@ argument specifies what operation to perform, and can be one of the following values:
HTCOOFF
Ä‰IDX1277Š@�”˜Suspend transmission of output. ‰IDX1278Š
ÂH�”˜TCOON
Ä@Restart transmission of output. ‰IDX1279Š
ÂH�”˜TCIOFF
Ä@Transmit a STOP character. ‰IDX1280Š
ÂH�”˜TCION
Ä@Transmit a START character.Â

For more information about the STOP and START characters, see section ‰ŠP�”›Special Characters@�”˜.
The return value is normally zero. In the event of an error, a value of H-1@ is returned. The following Herrno@ error conditions are defined for this function:
HEBADF
Ä‰IDX1281Š@�”˜The Bfiledes@ is not a valid file descriptor. ‰IDX1282Š
ÂH�”˜ENOTTY
Ä@The Bfiledes@ is not associated with a terminal device. ‰IDX1283Š
ÂH�”˜EINVAL
Ä@A bad value was supplied as the Baction@ argument.Â
À

ˆ‰SEC252Št�”›Noncanonical Mode Example

@�”˜Here is an example program that shows how you can set up a terminal device to read single characters in noncanonical input mode, without echo. #include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>

/* Use this variable to remember original terminal attributes. */

struct termios saved_attributes;

void
reset_input_mode (void)
{
tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes);
}

void
set_input_mode (void)
{
struct termios tattr;
char *name;

/* Make sure stdin is a terminal. */
if (!isatty (STDIN_FILENO))
{
fprintf (stderr, "Not a terminal.\n");
exit (EXIT_FAILURE);
}

/* Save the terminal attributes so we can restore them later. */
tcgetattr (STDIN_FILENO, &saved_attributes);
atexit (reset_input_mode);

/* Set the funny terminal modes. */
tcgetattr (STDIN_FILENO, &tattr);
tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
tattr.c_cc[VMIN] = 1;
tattr.c_cc[VTIME] = 0;
tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
}

int
main (void)
{
char c;

set_input_mode ();

while (1)
{
read (STDIN_FILENO, &c, 1);
if (c == '\004') /* HC-d@ */
break;
else
putchar (c);
}

return EXIT_SUCCESS;
}
This program is careful to restore the original terminal modes before exiting or terminating with a signal. It uses the Hatexit@ function (see section ‰ŠP�”›Cleanups on Exit@�”˜) to make sure this is done by Hexit@.
The shell is supposed to take care of resetting the terminal modes when a process is stopped or continued; see section ‰ŠP�”›Job Control@�”˜. But some existing shells do not actually do this, so you may wish to establish handlers for job control signals that reset terminal modes. The above example does so.
Œ
Go to the ‰ŠP�”›first@�”˜, ‰ŠP�”›previous@�”˜, ‰ŠP�”›next@�”˜, ‰ŠP�”›last@�”˜ section, ‰ŠP�”›table of contents@�”˜.