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