man-pages/man3/termios.3.html
2021-03-31 01:06:50 +01:00

1492 lines
32 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of TERMIOS</TITLE>
</HEAD><BODY>
<H1>TERMIOS</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed -
get and set terminal attributes, line control, get and set baud rate
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/termios.h">termios.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<B>int tcgetattr(int </B><I>fd</I><B>, struct termios *</B><I>termios_p</I><B>);</B>
<B>int tcsetattr(int </B><I>fd</I><B>, int </B><I>optional_actions</I><B>,</B>
<B> const struct termios *</B><I>termios_p</I><B>);</B>
<B>int tcsendbreak(int </B><I>fd</I><B>, int </B><I>duration</I><B>);</B>
<B>int tcdrain(int </B><I>fd</I><B>);</B>
<B>int tcflush(int </B><I>fd</I><B>, int </B><I>queue_selector</I><B>);</B>
<B>int tcflow(int </B><I>fd</I><B>, int </B><I>action</I><B>);</B>
<B>void cfmakeraw(struct termios *</B><I>termios_p</I><B>);</B>
<B>speed_t cfgetispeed(const struct termios *</B><I>termios_p</I><B>);</B>
<B>speed_t cfgetospeed(const struct termios *</B><I>termios_p</I><B>);</B>
<B>int cfsetispeed(struct termios *</B><I>termios_p</I><B>, speed_t </B><I>speed</I><B>);</B>
<B>int cfsetospeed(struct termios *</B><I>termios_p</I><B>, speed_t </B><I>speed</I><B>);</B>
<B>int cfsetspeed(struct termios *</B><I>termios_p</I><B>, speed_t </B><I>speed</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>cfsetspeed</B>(),
<B>cfmakeraw</B>():
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Since&nbsp;glibc&nbsp;2.19:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Glibc&nbsp;2.19&nbsp;and&nbsp;earlier:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_BSD_SOURCE
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The termios functions describe a general terminal interface that is
provided to control asynchronous communications ports.
<A NAME="lbAE">&nbsp;</A>
<H3>The termios structure</H3>
<P>
Many of the functions described here have a <I>termios_p</I> argument
that is a pointer to a <I>termios</I> structure.
This structure contains at least the following members:
<P>
tcflag_t c_iflag; /* input modes */
tcflag_t c_oflag; /* output modes */
tcflag_t c_cflag; /* control modes */
tcflag_t c_lflag; /* local modes */
cc_t c_cc[NCCS]; /* special characters */
<P>
The values that may be assigned to these fields are described below.
In the case of the first four bit-mask fields,
the definitions of some of the associated flags that may be set are
exposed only if a specific feature test macro (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7))
is defined, as noted in brackets (&quot;[]&quot;).
<P>
In the descriptions below, &quot;not in POSIX&quot; means that the
value is not specified in POSIX.1-2001,
and &quot;XSI&quot; means that the value is specified in POSIX.1-2001
as part of the XSI extension.
<P>
<I>c_iflag</I> flag constants:
<DL COMPACT>
<DT id="1"><B>IGNBRK</B>
<DD>
Ignore BREAK condition on input.
<DT id="2"><B>BRKINT</B>
<DD>
If <B>IGNBRK</B> is set, a BREAK is ignored.
If it is not set
but <B>BRKINT</B> is set, then a BREAK causes the input and output
queues to be flushed, and if the terminal is the controlling
terminal of a foreground process group, it will cause a
<B>SIGINT</B> to be sent to this foreground process group.
When neither <B>IGNBRK</B> nor <B>BRKINT</B> are set, a BREAK
reads as a null byte ('\0'), except when <B>PARMRK</B> is set,
in which case it reads as the sequence \377 \0 \0.
<DT id="3"><B>IGNPAR</B>
<DD>
Ignore framing errors and parity errors.
<DT id="4"><B>PARMRK</B>
<DD>
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
<B>INPCK</B> is set and <B>IGNPAR</B> is not set.
The way erroneous bytes are marked is with two preceding bytes,
\377 and \0.
Thus, the program actually reads three bytes for one
erroneous byte received from the terminal.
If a valid byte has the value \377,
and <B>ISTRIP</B> (see below) is not set,
the program might confuse it with the prefix that marks a
parity error.
Therefore, a valid byte \377 is passed to the program as two
bytes, \377 \377, in this case.
<DT id="5"><DD>
If neither <B>IGNPAR</B> nor <B>PARMRK</B>
is set, read a character with a parity error or framing error
as \0.
<DT id="6"><B>INPCK</B>
<DD>
Enable input parity checking.
<DT id="7"><B>ISTRIP</B>
<DD>
Strip off eighth bit.
<DT id="8"><B>INLCR</B>
<DD>
Translate NL to CR on input.
<DT id="9"><B>IGNCR</B>
<DD>
Ignore carriage return on input.
<DT id="10"><B>ICRNL</B>
<DD>
Translate carriage return to newline on input (unless <B>IGNCR</B> is set).
<DT id="11"><B>IUCLC</B>
<DD>
(not in POSIX) Map uppercase characters to lowercase on input.
<DT id="12"><B>IXON</B>
<DD>
Enable XON/XOFF flow control on output.
<DT id="13"><B>IXANY</B>
<DD>
(XSI) Typing any character will restart stopped output.
(The default is to allow just the START character to restart output.)
<DT id="14"><B>IXOFF</B>
<DD>
Enable XON/XOFF flow control on input.
<DT id="15"><B>IMAXBEL</B>
<DD>
(not in POSIX) Ring bell when input queue is full.
Linux does not implement this bit, and acts as if it is always set.
<DT id="16"><B>IUTF8</B> (since Linux 2.6.4)
<DD>
(not in POSIX) Input is UTF8;
this allows character-erase to be correctly performed in cooked mode.
</DL>
<P>
<I>c_oflag</I>
flag constants:
<DL COMPACT>
<DT id="17"><B>OPOST</B>
<DD>
Enable implementation-defined output processing.
<DT id="18"><B>OLCUC</B>
<DD>
(not in POSIX) Map lowercase characters to uppercase on output.
<DT id="19"><B>ONLCR</B>
<DD>
(XSI) Map NL to CR-NL on output.
<DT id="20"><B>OCRNL</B>
<DD>
Map CR to NL on output.
<DT id="21"><B>ONOCR</B>
<DD>
Don't output CR at column 0.
<DT id="22"><B>ONLRET</B>
<DD>
Don't output CR.
<DT id="23"><B>OFILL</B>
<DD>
Send fill characters for a delay, rather than using a timed delay.
<DT id="24"><B>OFDEL</B>
<DD>
Fill character is ASCII DEL (0177).
If unset, fill character is ASCII NUL ('\0').
(Not implemented on Linux.)
<DT id="25"><B>NLDLY</B>
<DD>
Newline delay mask.
Values are <B>NL0</B> and <B>NL1</B>.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>
or
<B>_XOPEN_SOURCE</B>]
<DT id="26"><B>CRDLY</B>
<DD>
Carriage return delay mask.
Values are <B>CR0</B>, <B>CR1</B>, <B>CR2</B>, or <B>CR3</B>.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>
or
<B>_XOPEN_SOURCE</B>]
<DT id="27"><B>TABDLY</B>
<DD>
Horizontal tab delay mask.
Values are <B>TAB0</B>, <B>TAB1</B>, <B>TAB2</B>, <B>TAB3</B> (or <B>XTABS</B>,
but see the
<B>BUGS</B>
section).
A value of TAB3, that is, XTABS, expands tabs to spaces
(with tab stops every eight columns).
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>
or
<B>_XOPEN_SOURCE</B>]
<DT id="28"><B>BSDLY</B>
<DD>
Backspace delay mask.
Values are <B>BS0</B> or <B>BS1</B>.
(Has never been implemented.)
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>
or
<B>_XOPEN_SOURCE</B>]
<DT id="29"><B>VTDLY</B>
<DD>
Vertical tab delay mask.
Values are <B>VT0</B> or <B>VT1</B>.
<DT id="30"><B>FFDLY</B>
<DD>
Form feed delay mask.
Values are <B>FF0</B> or <B>FF1</B>.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>
or
<B>_XOPEN_SOURCE</B>]
</DL>
<P>
<I>c_cflag</I> flag constants:
<DL COMPACT>
<DT id="31"><B>CBAUD</B>
<DD>
(not in POSIX) Baud speed mask (4+1 bits).
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="32"><B>CBAUDEX</B>
<DD>
(not in POSIX) Extra baud speed mask (1 bit), included in
<B>CBAUD</B>.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="33"><DD>
(POSIX says that the baud speed is stored in the
<I>termios</I>
structure without specifying where precisely, and provides
<B>cfgetispeed</B>()
and
<B>cfsetispeed</B>()
for getting at it.
Some systems use bits selected by
<B>CBAUD</B>
in
<I>c_cflag</I>,
other systems use separate fields, for example,
<I>sg_ispeed</I>
and
<I>sg_ospeed</I>.)
<DT id="34"><B>CSIZE</B>
<DD>
Character size mask.
Values are <B>CS5</B>, <B>CS6</B>, <B>CS7</B>, or <B>CS8</B>.
<DT id="35"><B>CSTOPB</B>
<DD>
Set two stop bits, rather than one.
<DT id="36"><B>CREAD</B>
<DD>
Enable receiver.
<DT id="37"><B>PARENB</B>
<DD>
Enable parity generation on output and parity checking for input.
<DT id="38"><B>PARODD</B>
<DD>
If set, then parity for input and output is odd;
otherwise even parity is used.
<DT id="39"><B>HUPCL</B>
<DD>
Lower modem control lines after last process closes the device (hang up).
<DT id="40"><B>CLOCAL</B>
<DD>
Ignore modem control lines.
<DT id="41"><B>LOBLK</B>
<DD>
(not in POSIX) Block output from a noncurrent shell layer.
For use by <B>shl</B> (shell layers). (Not implemented on Linux.)
<DT id="42"><B>CIBAUD</B>
<DD>
(not in POSIX) Mask for input speeds.
The values for the
<B>CIBAUD</B>
bits are
the same as the values for the
<B>CBAUD</B>
bits, shifted left
<B>IBSHIFT</B>
bits.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
(Not implemented on Linux.)
<DT id="43"><B>CMSPAR</B>
<DD>
(not in POSIX)
Use &quot;stick&quot; (mark/space) parity (supported on certain serial
devices): if
<B>PARODD</B>
is set, the parity bit is always 1; if
<B>PARODD</B>
is not set, then the parity bit is always 0.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="44"><B>CRTSCTS</B>
<DD>
(not in POSIX) Enable RTS/CTS (hardware) flow control.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
</DL>
<P>
<I>c_lflag</I> flag constants:
<DL COMPACT>
<DT id="45"><B>ISIG</B>
<DD>
When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
generate the corresponding signal.
<DT id="46"><B>ICANON</B>
<DD>
Enable canonical mode (described below).
<DT id="47"><B>XCASE</B>
<DD>
(not in POSIX; not supported under Linux)
If <B>ICANON</B> is also set, terminal is uppercase only.
Input is converted to lowercase, except for characters preceded by \.
On output, uppercase characters are preceded by \ and lowercase
characters are converted to uppercase.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>
or
<B>_XOPEN_SOURCE</B>]
<DT id="48"><B>ECHO</B>
<DD>
Echo input characters.
<DT id="49"><B>ECHOE</B>
<DD>
If <B>ICANON</B> is also set, the ERASE character erases the preceding
input character, and WERASE erases the preceding word.
<DT id="50"><B>ECHOK</B>
<DD>
If <B>ICANON</B> is also set, the KILL character erases the current line.
<DT id="51"><B>ECHONL</B>
<DD>
If <B>ICANON</B> is also set, echo the NL character even if ECHO is not set.
<DT id="52"><B>ECHOCTL</B>
<DD>
(not in POSIX) If <B>ECHO</B> is also set,
terminal special characters other than
TAB, NL, START, and STOP are echoed as <B>^X</B>,
where X is the character with
ASCII code 0x40 greater than the special character.
For example, character
0x08 (BS) is echoed as <B>^H</B>.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="53"><B>ECHOPRT</B>
<DD>
(not in POSIX) If <B>ICANON</B> and <B>ECHO</B> are also set, characters
are printed as they are being erased.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="54"><B>ECHOKE</B>
<DD>
(not in POSIX) If <B>ICANON</B> is also set, KILL is echoed by erasing
each character on the line, as specified by <B>ECHOE</B> and <B>ECHOPRT</B>.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="55"><B>DEFECHO</B>
<DD>
(not in POSIX) Echo only when a process is reading.
(Not implemented on Linux.)
<DT id="56"><B>FLUSHO</B>
<DD>
(not in POSIX; not supported under Linux)
Output is being flushed.
This flag is toggled by typing
the DISCARD character.
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="57"><B>NOFLSH</B>
<DD>
Disable flushing the input and output queues when generating signals for the
INT, QUIT, and SUSP characters.
<DT id="58"><B>TOSTOP</B>
<DD>
Send the
<B>SIGTTOU</B>
signal to the process group of a background process
which tries to write to its controlling terminal.
<DT id="59"><B>PENDIN</B>
<DD>
(not in POSIX; not supported under Linux)
All characters in the input queue are reprinted when
the next character is read.
(<B><A HREF="/cgi-bin/man/man2html?1+bash">bash</A></B>(1)
handles typeahead this way.)
[requires
<B>_BSD_SOURCE</B>
or
<B>_SVID_SOURCE</B>]
<DT id="60"><B>IEXTEN</B>
<DD>
Enable implementation-defined input processing.
This flag, as well as <B>ICANON</B> must be enabled for the
special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted,
and for the <B>IUCLC</B> flag to be effective.
</DL>
<P>
The <I>c_cc</I> array defines the terminal special characters.
The symbolic indices (initial values) and meaning are:
<DL COMPACT>
<DT id="61"><B>VDISCARD</B>
<DD>
(not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
Toggle: start/stop discarding pending output.
Recognized when
<B>IEXTEN</B>
is set, and then not passed as input.
<DT id="62"><B>VDSUSP</B>
<DD>
(not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
Delayed suspend character (DSUSP):
send
<B>SIGTSTP</B>
signal when the character is read by the user program.
Recognized when
<B>IEXTEN</B>
and
<B>ISIG</B>
are set, and the system supports
job control, and then not passed as input.
<DT id="63"><B>VEOF</B>
<DD>
(004, EOT, Ctrl-D)
End-of-file character (EOF).
More precisely: this character causes the pending tty buffer to be sent
to the waiting user program without waiting for end-of-line.
If it is the first character of the line, the
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
in the user program returns 0, which signifies end-of-file.
Recognized when
<B>ICANON</B>
is set, and then not passed as input.
<DT id="64"><B>VEOL</B>
<DD>
(0, NUL)
Additional end-of-line character (EOL).
Recognized when
<B>ICANON</B>
is set.
<DT id="65"><B>VEOL2</B>
<DD>
(not in POSIX; 0, NUL)
Yet another end-of-line character (EOL2).
Recognized when
<B>ICANON</B>
is set.
<DT id="66"><B>VERASE</B>
<DD>
(0177, DEL, rubout, or 010, BS, Ctrl-H, or also #)
Erase character (ERASE).
This erases the previous not-yet-erased character,
but does not erase past EOF or beginning-of-line.
Recognized when
<B>ICANON</B>
is set, and then not passed as input.
<DT id="67"><B>VINTR</B>
<DD>
(003, ETX, Ctrl-C, or also 0177, DEL, rubout)
Interrupt character (INTR).
Send a
<B>SIGINT</B>
signal.
Recognized when
<B>ISIG</B>
is set, and then not passed as input.
<DT id="68"><B>VKILL</B>
<DD>
(025, NAK, Ctrl-U, or Ctrl-X, or also @)
Kill character (KILL).
This erases the input since the last EOF or beginning-of-line.
Recognized when
<B>ICANON</B>
is set, and then not passed as input.
<DT id="69"><B>VLNEXT</B>
<DD>
(not in POSIX; 026, SYN, Ctrl-V)
Literal next (LNEXT).
Quotes the next input character, depriving it of
a possible special meaning.
Recognized when
<B>IEXTEN</B>
is set, and then not passed as input.
<DT id="70"><B>VMIN</B>
<DD>
Minimum number of characters for noncanonical read (MIN).
<DT id="71"><B>VQUIT</B>
<DD>
(034, FS, Ctrl-\)
Quit character (QUIT).
Send
<B>SIGQUIT</B>
signal.
Recognized when
<B>ISIG</B>
is set, and then not passed as input.
<DT id="72"><B>VREPRINT</B>
<DD>
(not in POSIX; 022, DC2, Ctrl-R)
Reprint unread characters (REPRINT).
Recognized when
<B>ICANON</B>
and
<B>IEXTEN</B>
are set, and then not passed as input.
<DT id="73"><B>VSTART</B>
<DD>
(021, DC1, Ctrl-Q)
Start character (START).
Restarts output stopped by the Stop character.
Recognized when
<B>IXON</B>
is set, and then not passed as input.
<DT id="74"><B>VSTATUS</B>
<DD>
(not in POSIX; not supported under Linux;
status request: 024, DC4, Ctrl-T).
Status character (STATUS).
Display status information at terminal,
including state of foreground process and amount of CPU time it has consumed.
Also sends a
<B>SIGINFO</B>
signal (not supported on Linux) to the foreground process group.
<DT id="75"><B>VSTOP</B>
<DD>
(023, DC3, Ctrl-S)
Stop character (STOP).
Stop output until Start character typed.
Recognized when
<B>IXON</B>
is set, and then not passed as input.
<DT id="76"><B>VSUSP</B>
<DD>
(032, SUB, Ctrl-Z)
Suspend character (SUSP).
Send
<B>SIGTSTP</B>
signal.
Recognized when
<B>ISIG</B>
is set, and then not passed as input.
<DT id="77"><B>VSWTCH</B>
<DD>
(not in POSIX; not supported under Linux; 0, NUL)
Switch character (SWTCH).
Used in System V to switch shells in
<I>shell layers</I>,
a predecessor to shell job control.
<DT id="78"><B>VTIME</B>
<DD>
Timeout in deciseconds for noncanonical read (TIME).
<DT id="79"><B>VWERASE</B>
<DD>
(not in POSIX; 027, ETB, Ctrl-W)
Word erase (WERASE).
Recognized when
<B>ICANON</B>
and
<B>IEXTEN</B>
are set, and then not passed as input.
</DL>
<P>
An individual terminal special character can be disabled by setting
the value of the corresponding
<I>c_cc</I>
element to
<B>_POSIX_VDISABLE</B>.
<P>
The above symbolic subscript values are all different, except that
<B>VTIME</B>,
<B>VMIN</B>
may have the same value as
<B>VEOL</B>,
<B>VEOF</B>,
respectively.
In noncanonical mode the special character meaning is replaced
by the timeout meaning.
For an explanation of
<B>VMIN</B>
and
<B>VTIME</B>,
see the description of
noncanonical mode below.
<A NAME="lbAF">&nbsp;</A>
<H3>Retrieving and changing terminal settings</H3>
<P>
<B>tcgetattr</B>()
gets the parameters associated with the object referred by <I>fd</I> and
stores them in the <I>termios</I> structure referenced by
<I>termios_p</I>.
This function may be invoked from a background process;
however, the terminal attributes may be subsequently changed by a
foreground process.
<P>
<B>tcsetattr</B>()
sets the parameters associated with the terminal (unless support is
required from the underlying hardware that is not available) from the
<I>termios</I> structure referred to by <I>termios_p</I>.
<I>optional_actions</I> specifies when the changes take effect:
<DL COMPACT>
<DT id="80"><B>TCSANOW</B><DD>
the change occurs immediately.
<DT id="81"><B>TCSADRAIN</B><DD>
the change occurs after all output written to
<I>fd</I>
has been transmitted.
This option should be used when changing
parameters that affect output.
<DT id="82"><B>TCSAFLUSH</B><DD>
the change occurs after all output written to the object referred by
<I>fd</I>
has been transmitted, and all input that has been received but not read
will be discarded before the change is made.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H3>Canonical and noncanonical mode</H3>
The setting of the
<B>ICANON</B>
canon flag in
<I>c_lflag</I>
determines whether the terminal is operating in canonical mode
(<B>ICANON</B>
set) or
noncanonical mode
(<B>ICANON</B>
unset).
By default,
<B>ICANON</B>
is set.
<P>
In canonical mode:
<DL COMPACT>
<DT id="83">*<DD>
Input is made available line by line.
An input line is available when one of the line delimiters
is typed (NL, EOL, EOL2; or EOF at the start of line).
Except in the case of EOF, the line delimiter is included
in the buffer returned by
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2).
<DT id="84">*<DD>
Line editing is enabled (ERASE, KILL;
and if the
<B>IEXTEN</B>
flag is set: WERASE, REPRINT, LNEXT).
A
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
returns at most one line of input; if the
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
requested fewer bytes than are available in the current line of input,
then only as many bytes as requested are read,
and the remaining characters will be available for a future
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2).
<DT id="85">*<DD>
The maximum line length is 4096 chars
(including the terminating newline character);
lines longer than 4096 chars are truncated.
After 4095 characters, input processing (e.g.,
<B>ISIG</B>
and
<B>ECHO*</B>
processing) continues, but any input data after 4095 characters up to
(but not including) any terminating newline is discarded.
This ensures that the terminal can always receive
more input until at least one line can be read.
</DL>
<P>
In noncanonical mode input is available immediately (without
the user having to type a line-delimiter character),
no input processing is performed,
and line editing is disabled.
The read buffer will only accept 4095 chars; this provides the
necessary space for a newline char if the input mode is switched
to canonical.
The settings of MIN
(<I>c_cc[VMIN]</I>)
and TIME
(<I>c_cc[VTIME]</I>)
determine the circumstances in which a
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
completes; there are four distinct cases:
<DL COMPACT>
<DT id="86">MIN == 0, TIME == 0 (polling read)<DD>
If data is available,
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
returns immediately, with the lesser of the number of bytes
available, or the number of bytes requested.
If no data is available,
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
returns 0.
<DT id="87">MIN &gt; 0, TIME == 0 (blocking read)<DD>
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
blocks until MIN bytes are available,
and returns up to the number of bytes requested.
<DT id="88">MIN == 0, TIME &gt; 0 (read with timeout)<DD>
TIME specifies the limit for a timer in tenths of a second.
The timer is started when
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
is called.
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
returns either when at least one byte of data is available,
or when the timer expires.
If the timer expires without any input becoming available,
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
returns 0.
If data is already available at the time of the call to
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2),
the call behaves as though the data was received immediately after the call.
<DT id="89">MIN &gt; 0, TIME &gt; 0 (read with interbyte timeout)<DD>
TIME specifies the limit for a timer in tenths of a second.
Once an initial byte of input becomes available,
the timer is restarted after each further byte is received.
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
returns when any of the following conditions is met:
<DL COMPACT><DT id="90"><DD>
<DL COMPACT>
<DT id="91">*<DD>
MIN bytes have been received.
<DT id="92">*<DD>
The interbyte timer expires.
<DT id="93">*<DD>
The number of bytes requested by
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
has been received.
(POSIX does not specify this termination condition,
and on some other implementations
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
does not return in this case.)
</DL>
</DL>
<DT id="94"><DD>
Because the timer is started only after the initial byte
becomes available, at least one byte will be read.
If data is already available at the time of the call to
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2),
the call behaves as though the data was received immediately after the call.
</DL>
<P>
POSIX
does not specify whether the setting of the
<B>O_NONBLOCK</B>
file status flag takes precedence over the MIN and TIME settings.
If
<B>O_NONBLOCK</B>
is set, a
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
in noncanonical mode may return immediately,
regardless of the setting of MIN or TIME.
Furthermore, if no data is available,
POSIX permits a
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
in noncanonical mode to return either 0, or -1 with
<I>errno</I>
set to
<B>EAGAIN</B>.
<A NAME="lbAH">&nbsp;</A>
<H3>Raw mode</H3>
<P>
<B>cfmakeraw</B>()
sets the terminal to something like the
&quot;raw&quot; mode of the old Version 7 terminal driver:
input is available character by character,
echoing is disabled, and all special processing of
terminal input and output characters is disabled.
The terminal attributes are set as follows:
<P>
termios_p-&gt;c_iflag &amp;= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;INLCR&nbsp;|&nbsp;IGNCR&nbsp;|&nbsp;ICRNL&nbsp;|&nbsp;IXON);
termios_p-&gt;c_oflag &amp;= ~OPOST;
termios_p-&gt;c_lflag &amp;= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
termios_p-&gt;c_cflag &amp;= ~(CSIZE | PARENB);
termios_p-&gt;c_cflag |= CS8;
<A NAME="lbAI">&nbsp;</A>
<H3>Line control</H3>
<P>
<B>tcsendbreak</B>()
transmits a continuous stream of zero-valued bits for a specific
duration, if the terminal is using asynchronous serial data
transmission.
If <I>duration</I> is zero, it transmits zero-valued bits
for at least 0.25 seconds, and not more that 0.5 seconds.
If <I>duration</I> is not zero, it sends zero-valued bits for some
implementation-defined length of time.
<P>
If the terminal is not using asynchronous serial data transmission,
<B>tcsendbreak</B>()
returns without taking any action.
<P>
<B>tcdrain</B>()
waits until all output written to the object referred to by
<I>fd</I>
has been transmitted.
<P>
<B>tcflush</B>()
discards data written to the object referred to by
<I>fd</I>
but not transmitted, or data received but not read, depending on the
value of
<I>queue_selector</I>:
<DL COMPACT>
<DT id="95"><B>TCIFLUSH</B><DD>
flushes data received but not read.
<DT id="96"><B>TCOFLUSH</B><DD>
flushes data written but not transmitted.
<DT id="97"><B>TCIOFLUSH</B><DD>
flushes both data received but not read, and data written but not
transmitted.
</DL>
<P>
<B>tcflow</B>()
suspends transmission or reception of data on the object referred to by
<I>fd</I>,
depending on the value of
<I>action</I>:
<DL COMPACT>
<DT id="98"><B>TCOOFF</B><DD>
suspends output.
<DT id="99"><B>TCOON</B><DD>
restarts suspended output.
<DT id="100"><B>TCIOFF</B><DD>
transmits a STOP character, which stops the terminal device from
transmitting data to the system.
<DT id="101"><B>TCION</B><DD>
transmits a START character, which starts the terminal device
transmitting data to the system.
</DL>
<P>
The default on open of a terminal file is that neither its input nor its
output is suspended.
<A NAME="lbAJ">&nbsp;</A>
<H3>Line speed</H3>
The baud rate functions are provided for getting and setting the values
of the input and output baud rates in the <I>termios</I> structure.
The new values do not take effect
until
<B>tcsetattr</B>()
is successfully called.
<P>
Setting the speed to <B>B0</B> instructs the modem to &quot;hang up&quot;.
The actual bit rate corresponding to <B>B38400</B> may be altered with
<B><A HREF="/cgi-bin/man/man2html?8+setserial">setserial</A></B>(8).
<P>
The input and output baud rates are stored in the <I>termios</I>
structure.
<P>
<B>cfgetospeed</B>()
returns the output baud rate stored in the <I>termios</I> structure
pointed to by
<I>termios_p</I>.
<P>
<B>cfsetospeed</B>()
sets the output baud rate stored in the <I>termios</I> structure pointed
to by <I>termios_p</I> to <I>speed</I>, which must be one of these constants:
<P>
<PRE>
<B> B0
B50
B75
B110
B134
B150
B200
B300
B600
B1200
B1800
B2400
B4800
B9600
B19200
B38400
B57600
B115200
B230400
</B></PRE>
<P>
The zero baud rate, <B>B0</B>,
is used to terminate the connection.
If B0 is specified, the modem control lines shall no longer be asserted.
Normally, this will disconnect the line.
<B>CBAUDEX</B> is a mask
for the speeds beyond those defined in POSIX.1 (57600 and above).
Thus, <B>B57600</B> &amp; <B>CBAUDEX</B> is nonzero.
<P>
<B>cfgetispeed</B>()
returns the input baud rate stored in the <I>termios</I> structure.
<P>
<B>cfsetispeed</B>()
sets the input baud rate stored in the <I>termios</I> structure to
<I>speed</I>,
which must be specified as one of the <B>Bnnn</B> constants listed above for
<B>cfsetospeed</B>().
If the input baud rate is set to zero, the input baud rate will be
equal to the output baud rate.
<P>
<B>cfsetspeed</B>()
is a 4.4BSD extension.
It takes the same arguments as
<B>cfsetispeed</B>(),
and sets both input and output speed.
<A NAME="lbAK">&nbsp;</A>
<H2>RETURN VALUE</H2>
<P>
<B>cfgetispeed</B>()
returns the input baud rate stored in the
<I>termios</I>
structure.
<P>
<B>cfgetospeed</B>()
returns the output baud rate stored in the <I>termios</I> structure.
<P>
All other functions return:
<DL COMPACT>
<DT id="102">0<DD>
on success.
<DT id="103">-1<DD>
on failure and set
<I>errno</I>
to indicate the error.
</DL>
<P>
Note that
<B>tcsetattr</B>()
returns success if <I>any</I> of the requested changes could be
successfully carried out.
Therefore, when making multiple changes
it may be necessary to follow this call with a further call to
<B>tcgetattr</B>()
to check that all changes have been performed successfully.
<A NAME="lbAL">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>tcgetattr</B>(),
<B>tcsetattr</B>(),
<B>tcdrain</B>(),
<B>tcflush</B>(),
<B>tcflow</B>(),
<B>tcsendbreak</B>(),
<B>cfmakeraw</B>(),
<B>cfgetispeed</B>(),
<B>cfgetospeed</B>(),
<B>cfsetispeed</B>(),
<B>cfsetospeed</B>(),
<B>cfsetspeed</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAM">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>tcgetattr</B>(),
<B>tcsetattr</B>(),
<B>tcsendbreak</B>(),
<B>tcdrain</B>(),
<B>tcflush</B>(),
<B>tcflow</B>(),
<B>cfgetispeed</B>(),
<B>cfgetospeed</B>(),
<B>cfsetispeed</B>(),
and
<B>cfsetospeed</B>()
are specified in POSIX.1-2001.
<P>
<B>cfmakeraw</B>()
and
<B>cfsetspeed</B>()
are nonstandard, but available on the BSDs.
<A NAME="lbAN">&nbsp;</A>
<H2>NOTES</H2>
UNIX&nbsp;V7 and several later systems have a list of baud rates
where after the fourteen values B0, ..., B9600 one finds the
two constants EXTA, EXTB (&quot;External A&quot; and &quot;External B&quot;).
Many systems extend the list with much higher baud rates.
<P>
The effect of a nonzero <I>duration</I> with
<B>tcsendbreak</B>()
varies.
SunOS specifies a break of
<I>duration&nbsp;*&nbsp;N</I>
seconds, where <I>N</I> is at least 0.25, and not more than 0.5.
Linux, AIX, DU, Tru64 send a break of
<I>duration</I>
milliseconds.
FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
<I>duration</I>.
Under Solaris and UnixWare,
<B>tcsendbreak</B>()
with nonzero
<I>duration</I>
behaves like
<B>tcdrain</B>().
<A NAME="lbAO">&nbsp;</A>
<H2>BUGS</H2>
On the Alpha architecture before Linux 4.16 (and glibc before 2.28), the
<B>XTABS</B>
value was different from
<B>TAB3</B>
and it was ignored by the
<B>N_TTY</B>
line discipline code of the terminal driver as a result
(because as it wasn't part of the
<B>TABDLY</B>
mask).
<A NAME="lbAP">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+reset">reset</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+setterm">setterm</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+stty">stty</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+tput">tput</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+tset">tset</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+tty">tty</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+ioctl_console">ioctl_console</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+ioctl_tty">ioctl_tty</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?8+setserial">setserial</A></B>(8)
<A NAME="lbAQ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="104"><A HREF="#lbAB">NAME</A><DD>
<DT id="105"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="106"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DL>
<DT id="107"><A HREF="#lbAE">The termios structure</A><DD>
<DT id="108"><A HREF="#lbAF">Retrieving and changing terminal settings</A><DD>
<DT id="109"><A HREF="#lbAG">Canonical and noncanonical mode</A><DD>
<DT id="110"><A HREF="#lbAH">Raw mode</A><DD>
<DT id="111"><A HREF="#lbAI">Line control</A><DD>
<DT id="112"><A HREF="#lbAJ">Line speed</A><DD>
</DL>
<DT id="113"><A HREF="#lbAK">RETURN VALUE</A><DD>
<DT id="114"><A HREF="#lbAL">ATTRIBUTES</A><DD>
<DT id="115"><A HREF="#lbAM">CONFORMING TO</A><DD>
<DT id="116"><A HREF="#lbAN">NOTES</A><DD>
<DT id="117"><A HREF="#lbAO">BUGS</A><DD>
<DT id="118"><A HREF="#lbAP">SEE ALSO</A><DD>
<DT id="119"><A HREF="#lbAQ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:58 GMT, March 31, 2021
</BODY>
</HTML>