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