]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/termios.3
termios.3: Add missing details on behaviour of PARMRK
[thirdparty/man-pages.git] / man3 / termios.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1993 Michael Haardt
2.\" (michael@moria.de)
3.\" Fri Apr 2 11:32:09 MET DST 1993
4.\"
1dd72f9c 5.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
6.\" This is free documentation; you can redistribute it and/or
7.\" modify it under the terms of the GNU General Public License as
8.\" published by the Free Software Foundation; either version 2 of
9.\" the License, or (at your option) any later version.
10.\"
11.\" The GNU General Public License's references to "object code"
12.\" and "executables" are to be interpreted as the output of any
13.\" document formatting or typesetting system, including
14.\" intermediate and printed output.
15.\"
16.\" This manual is distributed in the hope that it will be useful,
17.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19.\" GNU General Public License for more details.
20.\"
21.\" You should have received a copy of the GNU General Public
c715f741
MK
22.\" License along with this manual; if not, see
23.\" <http://www.gnu.org/licenses/>.
6a8d8745 24.\" %%%LICENSE_END
fea681da
MK
25.\"
26.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
27.\" Modified 1995-02-25 by Jim Van Zandt <jrv@vanzandt.mv.com>
28.\" Modified 1995-09-02 by Jim Van Zandt <jrv@vanzandt.mv.com>
29.\" moved to man3, aeb, 950919
c11b1abf 30.\" Modified 2001-09-22 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
31.\" Modified 2001-12-17, aeb
32.\" Modified 2004-10-31, aeb
19ab0376
MK
33.\" 2006-12-28, mtk:
34.\" Added .SS headers to give some structure to this page; and a
35.\" small amount of reordering.
a6712802 36.\" Added a section on canonical and noncanonical mode.
19ab0376
MK
37.\" Enhanced the discussion of "raw" mode for cfmakeraw().
38.\" Document CMSPAR.
2d7c8f1f
OT
39.\" 2015-11-04, Olivier TARTROU <olivier.tartrou@gmail.com>:
40.\" Reworked description of PARMRK from https://www.gnu.org/software/libc/manual/html_node/Input-Modes.html#Input-Modes
fea681da 41.\"
fe0fefbf 42.TH TERMIOS 3 2015-03-02 "Linux" "Linux Programmer's Manual"
fea681da
MK
43.SH NAME
44termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
45cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed \-
46get and set terminal attributes, line control, get and set baud rate
47.SH SYNOPSIS
04bb6cc0 48.nf
c91e381d 49.B #include <termios.h>
fea681da 50.br
c91e381d 51.B #include <unistd.h>
fea681da
MK
52.sp
53.BI "int tcgetattr(int " fd ", struct termios *" termios_p );
54.sp
04bb6cc0
MK
55.BI "int tcsetattr(int " fd ", int " optional_actions ,
56.BI " const struct termios *" termios_p );
fea681da
MK
57.sp
58.BI "int tcsendbreak(int " fd ", int " duration );
59.sp
60.BI "int tcdrain(int " fd );
61.sp
62.BI "int tcflush(int " fd ", int " queue_selector );
63.sp
64.BI "int tcflow(int " fd ", int " action );
65.sp
66.BI "void cfmakeraw(struct termios *" termios_p );
67.sp
68.BI "speed_t cfgetispeed(const struct termios *" termios_p );
69.sp
70.BI "speed_t cfgetospeed(const struct termios *" termios_p );
71.sp
72.BI "int cfsetispeed(struct termios *" termios_p ", speed_t " speed );
73.sp
74.BI "int cfsetospeed(struct termios *" termios_p ", speed_t " speed );
01d5d366 75.sp
52dab97a 76.BI "int cfsetspeed(struct termios *" termios_p ", speed_t " speed );
04bb6cc0 77.fi
cc4615cc
MK
78.sp
79.in -4n
80Feature Test Macro Requirements for glibc (see
81.BR feature_test_macros (7)):
82.in
83.sp
cc4615cc
MK
84.BR cfsetspeed (),
85.BR cfmakeraw ():
86_BSD_SOURCE
fea681da
MK
87.SH DESCRIPTION
88The termios functions describe a general terminal interface that is
89provided to control asynchronous communications ports.
73d8cece 90.SS The termios structure
fea681da
MK
91.LP
92Many of the functions described here have a \fItermios_p\fP argument
c13182ef
MK
93that is a pointer to a \fItermios\fP structure.
94This structure contains at least the following members:
fea681da 95.sp
a6e2f128 96.in +4n
fea681da 97.nf
bd9b2a9c
MK
98tcflag_t c_iflag; /* input modes */
99tcflag_t c_oflag; /* output modes */
100tcflag_t c_cflag; /* control modes */
101tcflag_t c_lflag; /* local modes */
d8b24e6e 102cc_t c_cc[NCCS]; /* special characters */
fea681da 103.fi
a6e2f128 104.in
fea681da 105.PP
869ebe5b 106The values that may be assigned to these fields are described below.
c13182ef
MK
107In the case of the first four bit-mask fields,
108the definitions of some of the associated flags that may be set are
33a0ccb2 109exposed only if a specific feature test macro (see
a8e7c990 110.BR feature_test_macros (7))
869ebe5b
MK
111is defined, as noted in brackets ("[]").
112.PP
42b09930 113In the descriptions below, "not in POSIX" means that the
c13182ef
MK
114value is not specified in POSIX.1-2001,
115and "XSI" means that the value is specified in POSIX.1-2001
42b09930
MK
116as part of the XSI extension.
117.PP
fea681da
MK
118\fIc_iflag\fP flag constants:
119.TP
120.B IGNBRK
121Ignore BREAK condition on input.
122.TP
123.B BRKINT
c13182ef
MK
124If \fBIGNBRK\fP is set, a BREAK is ignored.
125If it is not set
fea681da
MK
126but \fBBRKINT\fP is set, then a BREAK causes the input and output
127queues to be flushed, and if the terminal is the controlling
128terminal of a foreground process group, it will cause a
129\fBSIGINT\fP to be sent to this foreground process group.
130When neither \fBIGNBRK\fP nor \fBBRKINT\fP are set, a BREAK
f81fb444 131reads as a null byte (\(aq\\0\(aq), except when \fBPARMRK\fP is set,
fea681da
MK
132in which case it reads as the sequence \\377 \\0 \\0.
133.TP
134.B IGNPAR
135Ignore framing errors and parity errors.
136.TP
137.B PARMRK
2d7c8f1f
OT
138If this bit is set, input bytes with parity or framing errors are
139marked when passed to the program. This bit is meaningful only when
140\fBINPCK\fP is set and \fBIGNPAR\fP is not set.
141The way erroneous bytes are marked is with two preceding bytes,
142\\377 and \\0. Thus, the program actually reads three bytes for one
143erroneous byte received from the terminal.
144If a valid byte has the value \\377, and \fBISTRIP\fP (see below) is
145not set, the program might confuse it with the prefix that marks a
146parity error. So a valid byte \\377 is passed to the program as two
147bytes, \\377 \\377, in this case.
148
c13182ef 149If neither \fBIGNPAR\fP nor \fBPARMRK\fP
fea681da
MK
150is set, read a character with a parity error or framing error
151as \\0.
152.TP
153.B INPCK
154Enable input parity checking.
155.TP
156.B ISTRIP
157Strip off eighth bit.
158.TP
159.B INLCR
160Translate NL to CR on input.
161.TP
162.B IGNCR
163Ignore carriage return on input.
164.TP
165.B ICRNL
166Translate carriage return to newline on input (unless \fBIGNCR\fP is set).
167.TP
168.B IUCLC
169(not in POSIX) Map uppercase characters to lowercase on input.
170.TP
171.B IXON
172Enable XON/XOFF flow control on output.
173.TP
174.B IXANY
c13182ef 175(XSI) Typing any character will restart stopped output.
42b09930 176(The default is to allow just the START character to restart output.)
fea681da
MK
177.TP
178.B IXOFF
179Enable XON/XOFF flow control on input.
180.TP
181.B IMAXBEL
182(not in POSIX) Ring bell when input queue is full.
183Linux does not implement this bit, and acts as if it is always set.
225c76e9
MK
184.TP
185.BR IUTF8 " (since Linux 2.6.4)"
c13182ef 186(not in POSIX) Input is UTF8;
225c76e9 187this allows character-erase to be correctly performed in cooked mode.
fea681da 188.PP
73da3537
MK
189.I c_oflag
190flag constants:
fea681da
MK
191.TP
192.B OPOST
193Enable implementation-defined output processing.
fea681da
MK
194.TP
195.B OLCUC
196(not in POSIX) Map lowercase characters to uppercase on output.
197.TP
198.B ONLCR
199(XSI) Map NL to CR-NL on output.
200.TP
201.B OCRNL
202Map CR to NL on output.
203.TP
204.B ONOCR
205Don't output CR at column 0.
206.TP
207.B ONLRET
208Don't output CR.
209.TP
210.B OFILL
211Send fill characters for a delay, rather than using a timed delay.
212.TP
213.B OFDEL
ffcffad6 214Fill character is ASCII DEL (0177).
f81fb444 215If unset, fill character is ASCII NUL (\(aq\\0\(aq).
42b09930 216(Not implemented on Linux.)
fea681da
MK
217.TP
218.B NLDLY
c13182ef
MK
219Newline delay mask.
220Values are \fBNL0\fP and \fBNL1\fP.
db4e96b7
MK
221[requires
222.B _BSD_SOURCE
223or
224.B _SVID_SOURCE
c90511a6
MK
225or
226.BR _XOPEN_SOURCE ]
fea681da
MK
227.TP
228.B CRDLY
229Carriage return delay mask.
230Values are \fBCR0\fP, \fBCR1\fP, \fBCR2\fP, or \fBCR3\fP.
db4e96b7
MK
231[requires
232.B _BSD_SOURCE
233or
234.B _SVID_SOURCE
c90511a6
MK
235or
236.BR _XOPEN_SOURCE ]
fea681da
MK
237.TP
238.B TABDLY
239Horizontal tab delay mask.
240Values are \fBTAB0\fP, \fBTAB1\fP, \fBTAB2\fP, \fBTAB3\fP (or \fBXTABS\fP).
241A value of TAB3, that is, XTABS, expands tabs to spaces
242(with tab stops every eight columns).
db4e96b7
MK
243[requires
244.B _BSD_SOURCE
245or
246.B _SVID_SOURCE
c90511a6
MK
247or
248.BR _XOPEN_SOURCE ]
fea681da
MK
249.TP
250.B BSDLY
c13182ef
MK
251Backspace delay mask.
252Values are \fBBS0\fP or \fBBS1\fP.
fea681da 253(Has never been implemented.)
db4e96b7
MK
254[requires
255.B _BSD_SOURCE
256or
257.B _SVID_SOURCE
c90511a6
MK
258or
259.BR _XOPEN_SOURCE ]
fea681da
MK
260.TP
261.B VTDLY
c13182ef
MK
262Vertical tab delay mask.
263Values are \fBVT0\fP or \fBVT1\fP.
fea681da
MK
264.TP
265.B FFDLY
c13182ef
MK
266Form feed delay mask.
267Values are \fBFF0\fP or \fBFF1\fP.
db4e96b7
MK
268[requires
269.B _BSD_SOURCE
270or
271.B _SVID_SOURCE
c90511a6
MK
272or
273.BR _XOPEN_SOURCE ]
fea681da
MK
274.PP
275\fIc_cflag\fP flag constants:
276.TP
277.B CBAUD
278(not in POSIX) Baud speed mask (4+1 bits).
db4e96b7
MK
279[requires
280.B _BSD_SOURCE
c90511a6
MK
281or
282.BR _SVID_SOURCE ]
fea681da
MK
283.TP
284.B CBAUDEX
097585ed
MK
285(not in POSIX) Extra baud speed mask (1 bit), included in
286.BR CBAUD .
db4e96b7
MK
287[requires
288.B _BSD_SOURCE
c90511a6
MK
289or
290.BR _SVID_SOURCE ]
42b09930 291.sp
c13182ef
MK
292(POSIX says that the baud speed is stored in the
293.I termios
42b09930 294structure without specifying where precisely, and provides
63aa9df0 295.BR cfgetispeed ()
fea681da 296and
63aa9df0 297.BR cfsetispeed ()
c13182ef 298for getting at it.
097585ed
MK
299Some systems use bits selected by
300.B CBAUD
301in
fea681da 302.IR c_cflag ,
75b94dc3 303other systems use separate fields, for example,
fea681da
MK
304.I sg_ispeed
305and
306.IR sg_ospeed .)
307.TP
308.B CSIZE
309Character size mask.
310Values are \fBCS5\fP, \fBCS6\fP, \fBCS7\fP, or \fBCS8\fP.
311.TP
312.B CSTOPB
313Set two stop bits, rather than one.
314.TP
315.B CREAD
316Enable receiver.
317.TP
318.B PARENB
319Enable parity generation on output and parity checking for input.
320.TP
321.B PARODD
c13182ef 322If set, then parity for input and output is odd;
19ab0376 323otherwise even parity is used.
fea681da
MK
324.TP
325.B HUPCL
326Lower modem control lines after last process closes the device (hang up).
327.TP
328.B CLOCAL
329Ignore modem control lines.
330.TP
331.B LOBLK
24b74457 332(not in POSIX) Block output from a noncurrent shell layer.
42b09930 333For use by \fBshl\fP (shell layers). (Not implemented on Linux.)
fea681da
MK
334.TP
335.B CIBAUD
4a837837 336(not in POSIX) Mask for input speeds.
097585ed
MK
337The values for the
338.B CIBAUD
339bits are
340the same as the values for the
341.B CBAUD
342bits, shifted left
343.B IBSHIFT
344bits.
db4e96b7
MK
345[requires
346.B _BSD_SOURCE
c90511a6
MK
347or
348.BR _SVID_SOURCE ]
42b09930 349(Not implemented on Linux.)
fea681da 350.TP
adab6032 351.B CMSPAR
ad715af9 352(not in POSIX)
c13182ef 353Use "stick" (mark/space) parity (supported on certain serial
4a837837 354devices): if
c13182ef 355.B PARODD
adab6032 356is set, the parity bit is always 1; if
c13182ef 357.B PARODD
69ef1f65 358is not set, then the parity bit is always 0.
db4e96b7
MK
359[requires
360.B _BSD_SOURCE
c90511a6
MK
361or
362.BR _SVID_SOURCE ]
adab6032 363.TP
fea681da
MK
364.B CRTSCTS
365(not in POSIX) Enable RTS/CTS (hardware) flow control.
db4e96b7
MK
366[requires
367.B _BSD_SOURCE
c90511a6
MK
368or
369.BR _SVID_SOURCE ]
fea681da
MK
370.PP
371\fIc_lflag\fP flag constants:
372.TP
373.B ISIG
374When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
375generate the corresponding signal.
376.TP
377.B ICANON
c13182ef 378Enable canonical mode (described below).
fea681da
MK
379.TP
380.B XCASE
381(not in POSIX; not supported under Linux)
382If \fBICANON\fP is also set, terminal is uppercase only.
383Input is converted to lowercase, except for characters preceded by \\.
384On output, uppercase characters are preceded by \\ and lowercase
385characters are converted to uppercase.
6d1f5ca5
YK
386[requires
387.B _BSD_SOURCE
388or
389.B _SVID_SOURCE
390or
391.BR _XOPEN_SOURCE ]
c3dfd2c8 392.\" glibc is probably now wrong to allow
eee28e75
MK
393.\" Define
394.\" .B _XOPEN_SOURCE
395.\" to expose
396.\" .BR XCASE .
fea681da
MK
397.TP
398.B ECHO
399Echo input characters.
400.TP
401.B ECHOE
402If \fBICANON\fP is also set, the ERASE character erases the preceding
403input character, and WERASE erases the preceding word.
404.TP
405.B ECHOK
406If \fBICANON\fP is also set, the KILL character erases the current line.
407.TP
408.B ECHONL
409If \fBICANON\fP is also set, echo the NL character even if ECHO is not set.
410.TP
411.B ECHOCTL
d8b24e6e
MK
412(not in POSIX) If \fBECHO\fP is also set,
413terminal special characters other than
8bb93cd4
MK
414TAB, NL, START, and STOP are echoed as \fB^X\fP,
415where X is the character with
d8b24e6e 416ASCII code 0x40 greater than the special character.
c13182ef 417For example, character
8bb93cd4 4180x08 (BS) is echoed as \fB^H\fP.
db4e96b7
MK
419[requires
420.B _BSD_SOURCE
c90511a6
MK
421or
422.BR _SVID_SOURCE ]
fea681da
MK
423.TP
424.B ECHOPRT
96da8065 425(not in POSIX) If \fBICANON\fP and \fBECHO\fP are also set, characters
fea681da 426are printed as they are being erased.
db4e96b7
MK
427[requires
428.B _BSD_SOURCE
c90511a6
MK
429or
430.BR _SVID_SOURCE ]
fea681da
MK
431.TP
432.B ECHOKE
433(not in POSIX) If \fBICANON\fP is also set, KILL is echoed by erasing
434each character on the line, as specified by \fBECHOE\fP and \fBECHOPRT\fP.
db4e96b7
MK
435[requires
436.B _BSD_SOURCE
c90511a6
MK
437or
438.BR _SVID_SOURCE ]
fea681da
MK
439.TP
440.B DEFECHO
441(not in POSIX) Echo only when a process is reading.
42b09930 442(Not implemented on Linux.)
fea681da
MK
443.TP
444.B FLUSHO
445(not in POSIX; not supported under Linux)
c13182ef
MK
446Output is being flushed.
447This flag is toggled by typing
fea681da 448the DISCARD character.
db4e96b7
MK
449[requires
450.B _BSD_SOURCE
c90511a6
MK
451or
452.BR _SVID_SOURCE ]
fea681da
MK
453.TP
454.B NOFLSH
6e502d47
MK
455Disable flushing the input and output queues when generating signals for the
456INT, QUIT, and SUSP characters.
457.\" Stevens lets SUSP only flush the input queue
fea681da
MK
458.TP
459.B TOSTOP
8bd58774
MK
460Send the
461.B SIGTTOU
462signal to the process group of a background process
fea681da
MK
463which tries to write to its controlling terminal.
464.TP
465.B PENDIN
466(not in POSIX; not supported under Linux)
467All characters in the input queue are reprinted when
c13182ef 468the next character is read.
5852aba2
MK
469.RB ( bash (1)
470handles typeahead this way.)
db4e96b7
MK
471[requires
472.B _BSD_SOURCE
c90511a6
MK
473or
474.BR _SVID_SOURCE ]
fea681da
MK
475.TP
476.B IEXTEN
477Enable implementation-defined input processing.
0425de01 478This flag, as well as \fBICANON\fP must be enabled for the
fea681da
MK
479special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted,
480and for the \fBIUCLC\fP flag to be effective.
481.PP
d8b24e6e 482The \fIc_cc\fP array defines the terminal special characters.
fea681da
MK
483The symbolic indices (initial values) and meaning are:
484.TP
91e2779f
MK
485.B VDISCARD
486(not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
487Toggle: start/stop discarding pending output.
097585ed 488Recognized when
91e2779f 489.B IEXTEN
097585ed 490is set, and then not passed as input.
fea681da 491.TP
91e2779f
MK
492.B VDSUSP
493(not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
489e425d 494Delayed suspend character (DSUSP):
91e2779f
MK
495send
496.B SIGTSTP
497signal when the character is read by the user program.
097585ed 498Recognized when
91e2779f
MK
499.B IEXTEN
500and
097585ed 501.B ISIG
91e2779f
MK
502are set, and the system supports
503job control, and then not passed as input.
fea681da
MK
504.TP
505.B VEOF
506(004, EOT, Ctrl-D)
489e425d 507End-of-file character (EOF).
fea681da
MK
508More precisely: this character causes the pending tty buffer to be sent
509to the waiting user program without waiting for end-of-line.
d9c1ae64
MK
510If it is the first character of the line, the
511.BR read (2)
512in the user program returns 0, which signifies end-of-file.
097585ed
MK
513Recognized when
514.B ICANON
515is set, and then not passed as input.
fea681da 516.TP
fea681da
MK
517.B VEOL
518(0, NUL)
489e425d 519Additional end-of-line character (EOL).
097585ed
MK
520Recognized when
521.B ICANON
522is set.
fea681da 523.TP
fea681da
MK
524.B VEOL2
525(not in POSIX; 0, NUL)
489e425d 526Yet another end-of-line character (EOL2).
097585ed
MK
527Recognized when
528.B ICANON
529is set.
fea681da 530.TP
91e2779f
MK
531.B VERASE
532(0177, DEL, rubout, or 010, BS, Ctrl-H, or also #)
489e425d 533Erase character (ERASE).
91e2779f
MK
534This erases the previous not-yet-erased character,
535but does not erase past EOF or beginning-of-line.
097585ed 536Recognized when
91e2779f 537.B ICANON
097585ed 538is set, and then not passed as input.
fea681da 539.TP
91e2779f
MK
540.B VINTR
541(003, ETX, Ctrl-C, or also 0177, DEL, rubout)
489e425d 542Interrupt character (INTR).
91e2779f
MK
543Send a
544.B SIGINT
8bd58774 545signal.
097585ed
MK
546Recognized when
547.B ISIG
548is set, and then not passed as input.
fea681da 549.TP
91e2779f
MK
550.B VKILL
551(025, NAK, Ctrl-U, or Ctrl-X, or also @)
489e425d 552Kill character (KILL).
91e2779f 553This erases the input since the last EOF or beginning-of-line.
097585ed 554Recognized when
91e2779f
MK
555.B ICANON
556is set, and then not passed as input.
fea681da
MK
557.TP
558.B VLNEXT
559(not in POSIX; 026, SYN, Ctrl-V)
489e425d 560Literal next (LNEXT).
c13182ef 561Quotes the next input character, depriving it of
fea681da 562a possible special meaning.
097585ed
MK
563Recognized when
564.B IEXTEN
565is set, and then not passed as input.
fea681da 566.TP
91e2779f 567.B VMIN
489e425d 568Minimum number of characters for noncanonical read (MIN).
91e2779f
MK
569.TP
570.B VQUIT
31a6818e 571(034, FS, Ctrl-\e)
489e425d 572Quit character (QUIT).
91e2779f
MK
573Send
574.B SIGQUIT
575signal.
097585ed 576Recognized when
91e2779f
MK
577.B ISIG
578is set, and then not passed as input.
fea681da
MK
579.TP
580.B VREPRINT
581(not in POSIX; 022, DC2, Ctrl-R)
489e425d 582Reprint unread characters (REPRINT).
097585ed
MK
583Recognized when
584.B ICANON
585and
586.B IEXTEN
587are set, and then not passed as input.
fea681da 588.TP
91e2779f
MK
589.B VSTART
590(021, DC1, Ctrl-Q)
489e425d 591Start character (START).
91e2779f 592Restarts output stopped by the Stop character.
097585ed 593Recognized when
91e2779f 594.B IXON
097585ed 595is set, and then not passed as input.
fea681da
MK
596.TP
597.B VSTATUS
598(not in POSIX; not supported under Linux;
599status request: 024, DC4, Ctrl-T).
a6639d09
MK
600Status character (STATUS).
601Display status information at terminal,
602including state of foreground process and amount of CPU time it has consumed.
603Also sends a
604.BR SIGINFO
605signal (not supported on Linux) to the foreground process group.
91e2779f
MK
606.TP
607.B VSTOP
608(023, DC3, Ctrl-S)
489e425d 609Stop character (STOP).
91e2779f
MK
610Stop output until Start character typed.
611Recognized when
612.B IXON
613is set, and then not passed as input.
614.TP
615.B VSUSP
616(032, SUB, Ctrl-Z)
489e425d 617Suspend character (SUSP).
91e2779f
MK
618Send
619.B SIGTSTP
620signal.
621Recognized when
622.B ISIG
623is set, and then not passed as input.
624.TP
625.B VSWTCH
626(not in POSIX; not supported under Linux; 0, NUL)
489e425d 627Switch character (SWTCH).
33b7fff5
MK
628Used in System V to switch shells in
629.IR "shell layers" ,
5aaf78b7 630a predecessor to shell job control.
91e2779f
MK
631.TP
632.B VTIME
489e425d 633Timeout in deciseconds for noncanonical read (TIME).
91e2779f
MK
634.TP
635.B VWERASE
636(not in POSIX; 027, ETB, Ctrl-W)
489e425d 637Word erase (WERASE).
91e2779f
MK
638Recognized when
639.B ICANON
640and
641.B IEXTEN
642are set, and then not passed as input.
fea681da 643.LP
d51529b8
MK
644An individual terminal special character can be disabled by setting
645the value of the corresponding
646.I c_cc
647element to
648.BR _POSIX_VDISABLE .
649.LP
650The above symbolic subscript values are all different, except that
097585ed 651.BR VTIME ,
0daa9e92 652.B VMIN
097585ed 653may have the same value as
3cf81850 654.BR VEOL ,
097585ed
MK
655.BR VEOF ,
656respectively.
a6712802 657In noncanonical mode the special character meaning is replaced
c13182ef 658by the timeout meaning.
097585ed
MK
659For an explanation of
660.B VMIN
661and
662.BR VTIME ,
663see the description of
a6712802 664noncanonical mode below.
73d8cece 665.SS Retrieving and changing terminal settings
fea681da 666.PP
63aa9df0 667.BR tcgetattr ()
fea681da 668gets the parameters associated with the object referred by \fIfd\fP and
869ebe5b 669stores them in the \fItermios\fP structure referenced by
c13182ef
MK
670\fItermios_p\fP.
671This function may be invoked from a background process;
fea681da
MK
672however, the terminal attributes may be subsequently changed by a
673foreground process.
674.LP
63aa9df0 675.BR tcsetattr ()
fea681da
MK
676sets the parameters associated with the terminal (unless support is
677required from the underlying hardware that is not available) from the
c13182ef 678\fItermios\fP structure referred to by \fItermios_p\fP.
fea681da
MK
679\fIoptional_actions\fP specifies when the changes take effect:
680.IP \fBTCSANOW\fP
681the change occurs immediately.
682.IP \fBTCSADRAIN\fP
683the change occurs after all output written to
684.I fd
c13182ef 685has been transmitted.
d1c2e0f2 686This option should be used when changing
fea681da
MK
687parameters that affect output.
688.IP \fBTCSAFLUSH\fP
689the change occurs after all output written to the object referred by
690.I fd
691has been transmitted, and all input that has been received but not read
692will be discarded before the change is made.
73d8cece 693.SS Canonical and noncanonical mode
19ab0376
MK
694The setting of the
695.B ICANON
696canon flag in
697.I c_lflag
698determines whether the terminal is operating in canonical mode
699.RB ( ICANON
700set) or
a6712802 701noncanonical mode
c13182ef 702.RB ( ICANON
19ab0376
MK
703unset).
704By default,
705.B ICANON
706set.
707
708In canonical mode:
709.IP * 2
710Input is made available line by line.
711An input line is available when one of the line delimiters
712is typed (NL, EOL, EOL2; or EOF at the start of line).
713Except in the case of EOF, the line delimiter is included
714in the buffer returned by
715.BR read (2).
716.IP * 2
c13182ef
MK
717Line editing is enabled (ERASE, KILL;
718and if the
19ab0376
MK
719.B IEXTEN
720flag is set: WERASE, REPRINT, LNEXT).
c13182ef 721A
fb186734 722.BR read (2)
19ab0376 723returns at most one line of input; if the
fb186734 724.BR read (2)
19ab0376
MK
725requested fewer bytes than are available in the current line of input,
726then only as many bytes as requested are read,
727and the remaining characters will be available for a future
fb186734 728.BR read (2).
19ab0376 729.PP
a6712802 730In noncanonical mode input is available immediately (without
19ab0376 731the user having to type a line-delimiter character),
764d3de3 732no input processing is performed,
19ab0376 733and line editing is disabled.
c13182ef 734The settings of MIN
19ab0376 735.RI ( c_cc[VMIN] )
0f8b10eb 736and TIME
19ab0376
MK
737.RI ( c_cc[VTIME] )
738determine the circumstances in which a
739.BR read (2)
740completes; there are four distinct cases:
959c4b25 741.TP
f8f8b9c1 742MIN == 0, TIME == 0 (polling read)
19ab0376 743If data is available,
fb186734 744.BR read (2)
19ab0376
MK
745returns immediately, with the lesser of the number of bytes
746available, or the number of bytes requested.
747If no data is available,
fb186734 748.BR read (2)
19ab0376 749returns 0.
959c4b25 750.TP
f8f8b9c1 751MIN > 0, TIME == 0 (blocking read)
fb186734 752.BR read (2)
4b985dd6
MK
753blocks until MIN bytes are available,
754and returns up to the number of bytes requested.
959c4b25 755.TP
f8f8b9c1 756MIN == 0, TIME > 0 (read with timeout)
19ab0376 757TIME specifies the limit for a timer in tenths of a second.
c13182ef 758The timer is started when
fb186734 759.BR read (2)
19ab0376 760is called.
fb186734 761.BR read (2)
19ab0376
MK
762returns either when at least one byte of data is available,
763or when the timer expires.
764If the timer expires without any input becoming available,
fb186734 765.BR read (2)
19ab0376 766returns 0.
e764d1b7 767If data is already available at the time of the call to
8563c249 768.BR read (2),
e764d1b7 769the call behaves as though the data was received immediately after the call.
959c4b25 770.TP
f8f8b9c1 771MIN > 0, TIME > 0 (read with interbyte timeout)
19ab0376
MK
772TIME specifies the limit for a timer in tenths of a second.
773Once an initial byte of input becomes available,
774the timer is restarted after each further byte is received.
fb186734 775.BR read (2)
a9f0126f
MK
776returns when any of the following conditions is met:
777.RS
778.IP * 3
779MIN bytes have been received.
780.IP *
781The interbyte timer expires.
782.IP *
783The number of bytes requested by
784.BR read (2)
785has been received.
786(POSIX does not specify this termination condition,
787and on some other implementations
788.\" e.g., Solaris
8563c249 789.BR read (2)
a9f0126f
MK
790does not return in this case.)
791.RE
792.IP
33a0ccb2 793Because the timer is started only after the initial byte
19ab0376 794becomes available, at least one byte will be read.
e764d1b7 795If data is already available at the time of the call to
8563c249 796.BR read (2),
e764d1b7 797the call behaves as though the data was received immediately after the call.
5ee2d3c5
MK
798.PP
799POSIX
800.\" POSIX.1-2008 XBD 11.1.7
801does not specify whether the setting of the
802.B O_NONBLOCK
803file status flag takes precedence over the MIN and TIME settings.
804If
805.B O_NONBLOCK
806is set, a
8563c249 807.BR read (2)
5ee2d3c5
MK
808in noncanonical mode may return immediately,
809regardless of the setting of MIN or TIME.
810Furthermore, if no data is available,
811POSIX permits a
8563c249 812.BR read (2)
5ee2d3c5
MK
813in noncanonical mode to return either 0, or \-1 with
814.I errno
815set to
816.BR EAGAIN .
73d8cece 817.SS Raw mode
19ab0376 818.LP
60a90ecd
MK
819.BR cfmakeraw ()
820sets the terminal to something like the
1954b6a9 821"raw" mode of the old Version 7 terminal driver:
19ab0376 822input is available character by character,
c13182ef 823echoing is disabled, and all special processing of
19ab0376
MK
824terminal input and output characters is disabled.
825The terminal attributes are set as follows:
826.nf
827
94e9d9fe 828 termios_p\->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
19ab0376 829 | INLCR | IGNCR | ICRNL | IXON);
94e9d9fe
MK
830 termios_p\->c_oflag &= ~OPOST;
831 termios_p\->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
832 termios_p\->c_cflag &= ~(CSIZE | PARENB);
833 termios_p\->c_cflag |= CS8;
19ab0376 834.fi
73d8cece 835.SS Line control
fea681da 836.LP
63aa9df0 837.BR tcsendbreak ()
fea681da
MK
838transmits a continuous stream of zero-valued bits for a specific
839duration, if the terminal is using asynchronous serial data
c13182ef
MK
840transmission.
841If \fIduration\fP is zero, it transmits zero-valued bits
842for at least 0.25 seconds, and not more that 0.5 seconds.
843If \fIduration\fP is not zero, it sends zero-valued bits for some
fea681da
MK
844implementation-defined length of time.
845.LP
846If the terminal is not using asynchronous serial data transmission,
60a90ecd
MK
847.BR tcsendbreak ()
848returns without taking any action.
fea681da 849.LP
63aa9df0 850.BR tcdrain ()
fea681da
MK
851waits until all output written to the object referred to by
852.I fd
853has been transmitted.
854.LP
63aa9df0 855.BR tcflush ()
fea681da
MK
856discards data written to the object referred to by
857.I fd
858but not transmitted, or data received but not read, depending on the
859value of
860.IR queue_selector :
861.IP \fBTCIFLUSH\fP
862flushes data received but not read.
863.IP \fBTCOFLUSH\fP
864flushes data written but not transmitted.
865.IP \fBTCIOFLUSH\fP
866flushes both data received but not read, and data written but not
867transmitted.
868.LP
63aa9df0 869.BR tcflow ()
fea681da
MK
870suspends transmission or reception of data on the object referred to by
871.IR fd ,
872depending on the value of
873.IR action :
874.IP \fBTCOOFF\fP
875suspends output.
876.IP \fBTCOON\fP
877restarts suspended output.
878.IP \fBTCIOFF\fP
c13182ef 879transmits a STOP character, which stops the terminal device from
35478399 880transmitting data to the system.
fea681da 881.IP \fBTCION\fP
c13182ef 882transmits a START character, which starts the terminal device
35478399 883transmitting data to the system.
fea681da
MK
884.LP
885The default on open of a terminal file is that neither its input nor its
886output is suspended.
73d8cece 887.SS Line speed
87d1fd87 888The baud rate functions are provided for getting and setting the values
c13182ef
MK
889of the input and output baud rates in the \fItermios\fP structure.
890The new values do not take effect
60a90ecd
MK
891until
892.BR tcsetattr ()
893is successfully called.
87d1fd87
MK
894
895Setting the speed to \fBB0\fP instructs the modem to "hang up".
896The actual bit rate corresponding to \fBB38400\fP may be altered with
60a90ecd 897.BR setserial (8).
87d1fd87
MK
898.LP
899The input and output baud rates are stored in the \fItermios\fP
900structure.
fea681da 901.LP
63aa9df0 902.BR cfgetospeed ()
869ebe5b 903returns the output baud rate stored in the \fItermios\fP structure
fea681da
MK
904pointed to by
905.IR termios_p .
906.LP
63aa9df0 907.BR cfsetospeed ()
869ebe5b 908sets the output baud rate stored in the \fItermios\fP structure pointed
fea681da
MK
909to by \fItermios_p\fP to \fIspeed\fP, which must be one of these constants:
910.nf
869ebe5b 911
fea681da
MK
912.ft B
913 B0
914 B50
915 B75
916 B110
917 B134
918 B150
919 B200
920 B300
921 B600
922 B1200
923 B1800
924 B2400
925 B4800
926 B9600
927 B19200
928 B38400
929 B57600
930 B115200
931 B230400
932.ft P
869ebe5b 933
fea681da
MK
934.fi
935The zero baud rate, \fBB0\fP,
c13182ef
MK
936is used to terminate the connection.
937If B0 is specified, the modem control lines shall no longer be asserted.
be7fff26
MK
938Normally, this will disconnect the line.
939\fBCBAUDEX\fP is a mask
fea681da 940for the speeds beyond those defined in POSIX.1 (57600 and above).
c7094399 941Thus, \fBB57600\fP & \fBCBAUDEX\fP is nonzero.
fea681da 942.LP
63aa9df0 943.BR cfgetispeed ()
869ebe5b 944returns the input baud rate stored in the \fItermios\fP structure.
fea681da 945.LP
63aa9df0 946.BR cfsetispeed ()
869ebe5b 947sets the input baud rate stored in the \fItermios\fP structure to
c13182ef 948.IR speed ,
869ebe5b
MK
949which must be specified as one of the \fBBnnn\fP constants listed above for
950.BR cfsetospeed ().
fea681da
MK
951If the input baud rate is set to zero, the input baud rate will be
952equal to the output baud rate.
953.LP
63aa9df0 954.BR cfsetspeed ()
c13182ef
MK
955is a 4.4BSD extension.
956It takes the same arguments as
869ebe5b
MK
957.BR cfsetispeed (),
958and sets both input and output speed.
47297adb 959.SH RETURN VALUE
fea681da 960.LP
63aa9df0 961.BR cfgetispeed ()
fea681da 962returns the input baud rate stored in the
869ebe5b 963\fItermios\fP
fea681da
MK
964structure.
965.LP
63aa9df0 966.BR cfgetospeed ()
869ebe5b 967returns the output baud rate stored in the \fItermios\fP structure.
fea681da
MK
968.LP
969All other functions return:
970.IP 0
971on success.
972.IP \-1
973on failure and set
974.I errno
975to indicate the error.
976.LP
977Note that
f87925c6 978.BR tcsetattr ()
fea681da 979returns success if \fIany\fP of the requested changes could be
c13182ef
MK
980successfully carried out.
981Therefore, when making multiple changes
fea681da 982it may be necessary to follow this call with a further call to
f87925c6 983.BR tcgetattr ()
fea681da 984to check that all changes have been performed successfully.
2be8b1b2 985.SH ATTRIBUTES
146c2ef3
PH
986For an explanation of the terms used in this section, see
987.BR attributes (7).
988.nh
989.ad l
990.TS
991allbox;
b2a64861 992lbw36 lb lb
84a15261 993l l l.
146c2ef3
PH
994Interface Attribute Value
995T{
2be8b1b2
PH
996.BR tcgetattr (),
997.BR tcsetattr (),
2be8b1b2
PH
998.BR tcdrain (),
999.BR tcflush (),
ff548faa 1000.BR tcflow (),
b2a64861 1001.BR tcsendbreak (),
2be8b1b2
PH
1002.BR cfmakeraw (),
1003.BR cfgetispeed (),
1004.BR cfgetospeed (),
1005.BR cfsetispeed (),
1006.BR cfsetospeed (),
2be8b1b2 1007.BR cfsetspeed ()
b6c73e0b
ZL
1008.\" FIXME: the following markings are different from which in glibc manual,
1009.\" markings in glibc manual are more detailed.
1010.\" tcsendbreak: MT-Unsafe race:tcattr(filedes)/bsd
1011.\" tcflow: MT-Unsafe race:tcattr(filedes)/bsd
1012.\" glibc manual says /bsd indicate the preceding marker only applies
1013./" when the underlying kernel is a BSD kernel.
1014.\" So, it is safety in Linux kernel.
146c2ef3
PH
1015T} Thread safety MT-Safe
1016.TE
1017.ad
1018.hy
dfb631a8
MK
1019.SH CONFORMING TO
1020.BR tcgetattr (),
1021.BR tcsetattr (),
1022.BR tcsendbreak (),
1023.BR tcdrain (),
1024.BR tcflush (),
1025.BR tcflow (),
1026.BR cfgetispeed (),
1027.BR cfgetospeed (),
1028.BR cfsetispeed (),
1029and
1030.BR cfsetospeed ()
1031are specified in POSIX.1-2001.
1032
1033.BR cfmakeraw ()
01d5d366
MK
1034and
1035.BR cfsetspeed ()
c8f2dd47 1036are nonstandard, but available on the BSDs.
fea681da 1037.SH NOTES
b4112efb 1038UNIX\ V7 and several later systems have a list of baud rates
fea681da
MK
1039where after the fourteen values B0, ..., B9600 one finds the
1040two constants EXTA, EXTB ("External A" and "External B").
1041Many systems extend the list with much higher baud rates.
1042.LP
c7094399 1043The effect of a nonzero \fIduration\fP with
60a90ecd
MK
1044.BR tcsendbreak ()
1045varies.
c13182ef 1046SunOS specifies a break of
8b8d0001 1047.I "duration\ *\ N"
fea681da
MK
1048seconds, where \fIN\fP is at least 0.25, and not more than 0.5.
1049Linux, AIX, DU, Tru64 send a break of
1050.I duration
1051milliseconds.
1052FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
1053.IR duration .
1f409d5d 1054Under Solaris and UnixWare,
e511ffb6 1055.BR tcsendbreak ()
c7094399 1056with nonzero
fea681da
MK
1057.I duration
1058behaves like
e511ffb6 1059.BR tcdrain ().
fea681da
MK
1060.\" libc4 until 4.7.5, glibc for sysv: EINVAL for duration > 0.
1061.\" libc4.7.6, libc5, glibc for unix: duration in ms.
1062.\" glibc for bsd: duration in us
1063.\" glibc for sunos4: ignore duration
47297adb 1064.SH SEE ALSO
c04700fb
MK
1065.BR reset (1),
1066.BR setterm (1),
fea681da 1067.BR stty (1),
c04700fb 1068.BR tput (1),
ca8c33fc 1069.BR tset (1),
fe62e3de
MK
1070.BR console_ioctl (4),
1071.BR tty_ioctl (4),
fea681da 1072.BR setserial (8)