Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Input processing and reading data

&pagelevel(5)&pagelevel

A terminal associated with a special file may operate in full-duplex mode, so that input characters may be entered at any time, even while output is occurring. In the POSIX subsystem, full-duplex mode for terminals is simulated by TIAM.

Each special file of a terminal is associated with an input queue in which incoming data is stored by the system before being read by a process. The input is lost if the input queues of the system are full or if any input line exceeds the maximum number of bytes permitted for input (as defined by {MAX_INPUT}; see limits.h). {MAX_INPUT} must be greater than or equal to {_POSIX_MAX_CANON}. This value can be queried with pathconf().

Two general types of input processing are available, depending on whether the special file associated with the terminal device is in canonical mode or non-canonical mode. These modes are described in the next two sections on "Canonical mode input processing" and "Non-canonical mode input processing", respectively. Additionally, input characters are processed according to the settings of the c_iflag (see section “Input modes”) and c_lflag (see section “Local modes”) components. Such processing can include local echoing, which in general means that input characters are immediately transmitted back to the terminal when they are received from the terminal. This is particularly useful for terminals that operate in full-duplex mode.

If the O_NONBLOCK flag is clear, then read requests block until data is available or a signal has been received. If the O_NONBLOCK flag is set, then the read request is completed, without blocking, in one of three ways:

  • If there is enough data available to satisfy the entire request, the read() function completes successfully and returns the number of bytes read.

  • If there is not enough data available to satisfy the entire request, the read() function completes successfully, having read as much data as possible, and returns the number of bytes actually read.

  • If there is no data available, the read() function returns -1, with errno set to EAGAIN.

When data is available depends on whether the input processing mode is canonical or noncanonical. The following sections, Canonical mode input processing" and "Non-canonical mode input processing", describe each of these input processing modes.