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