Go to the previous, next section.

Two Styles of Input: Canonical or Not

POSIX systems support two basic modes of input: canonical and noncanonical.

In canonical input processing mode, terminal input is processed in lines terminated by newline ('\n'), EOF, or EOL characters. No input can be read until an entire line has been typed by the user, and the read function (see section 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: the ERASE and KILL characters are interpreted specially to perform editing operations within the current line of text. See section Characters for Input Editing.

The constants _POSIX_MAX_CANON and MAX_CANON parameterize the maximum number of bytes which may appear in a single line of canonical input. See section Limits on File System Capacity.

In noncanonical 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 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 ICANON flag in the c_lflag member of struct termios. See section Local Modes.

Go to the previous, next section.