localedef.1, access.2, ioctl_console.2, ioctl_fslabel.2, openat2.2, write.2, dlsym...
[man-pages.git] / man3 / termios.3
blob256236819a3eb11f9693010363f15621adc6c2a2
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).
335 (Not implemented on Linux.)
337 .B CIBAUD
338 (not in POSIX) Mask for input speeds.
339 The values for the
340 .B CIBAUD
341 bits are
342 the same as the values for the
343 .B CBAUD
344 bits, shifted left
345 .B IBSHIFT
346 bits.
347 [requires
348 .B _BSD_SOURCE
350 .BR _SVID_SOURCE ]
351 (Not implemented on Linux.)
353 .B CMSPAR
354 (not in POSIX)
355 Use "stick" (mark/space) parity (supported on certain serial
356 devices): if
357 .B PARODD
358 is set, the parity bit is always 1; if
359 .B PARODD
360 is not set, then the parity bit is always 0.
361 [requires
362 .B _BSD_SOURCE
364 .BR _SVID_SOURCE ]
366 .B CRTSCTS
367 (not in POSIX) Enable RTS/CTS (hardware) flow control.
368 [requires
369 .B _BSD_SOURCE
371 .BR _SVID_SOURCE ]
373 \fIc_lflag\fP flag constants:
375 .B ISIG
376 When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
377 generate the corresponding signal.
379 .B ICANON
380 Enable canonical mode (described below).
382 .B XCASE
383 (not in POSIX; not supported under Linux)
384 If \fBICANON\fP is also set, terminal is uppercase only.
385 Input is converted to lowercase, except for characters preceded by \e.
386 On output, uppercase characters are preceded by \e and lowercase
387 characters are converted to uppercase.
388 [requires
389 .B _BSD_SOURCE
391 .B _SVID_SOURCE
393 .BR _XOPEN_SOURCE ]
394 .\" glibc is probably now wrong to allow
395 .\" Define
396 .\" .B _XOPEN_SOURCE
397 .\" to expose
398 .\" .BR XCASE .
400 .B ECHO
401 Echo input characters.
403 .B ECHOE
404 If \fBICANON\fP is also set, the ERASE character erases the preceding
405 input character, and WERASE erases the preceding word.
407 .B ECHOK
408 If \fBICANON\fP is also set, the KILL character erases the current line.
410 .B ECHONL
411 If \fBICANON\fP is also set, echo the NL character even if ECHO is not set.
413 .B ECHOCTL
414 (not in POSIX) If \fBECHO\fP is also set,
415 terminal special characters other than
416 TAB, NL, START, and STOP are echoed as \fB\(haX\fP,
417 where X is the character with
418 ASCII code 0x40 greater than the special character.
419 For example, character
420 0x08 (BS) is echoed as \fB\(haH\fP.
421 [requires
422 .B _BSD_SOURCE
424 .BR _SVID_SOURCE ]
426 .B ECHOPRT
427 (not in POSIX) If \fBICANON\fP and \fBECHO\fP are also set, characters
428 are printed as they are being erased.
429 [requires
430 .B _BSD_SOURCE
432 .BR _SVID_SOURCE ]
434 .B ECHOKE
435 (not in POSIX) If \fBICANON\fP is also set, KILL is echoed by erasing
436 each character on the line, as specified by \fBECHOE\fP and \fBECHOPRT\fP.
437 [requires
438 .B _BSD_SOURCE
440 .BR _SVID_SOURCE ]
442 .B DEFECHO
443 (not in POSIX) Echo only when a process is reading.
444 (Not implemented on Linux.)
446 .B FLUSHO
447 (not in POSIX; not supported under Linux)
448 Output is being flushed.
449 This flag is toggled by typing
450 the DISCARD character.
451 [requires
452 .B _BSD_SOURCE
454 .BR _SVID_SOURCE ]
456 .B NOFLSH
457 Disable flushing the input and output queues when generating signals for the
458 INT, QUIT, and SUSP characters.
459 .\" Stevens lets SUSP only flush the input queue
461 .B TOSTOP
462 Send the
463 .B SIGTTOU
464 signal to the process group of a background process
465 which tries to write to its controlling terminal.
467 .B PENDIN
468 (not in POSIX; not supported under Linux)
469 All characters in the input queue are reprinted when
470 the next character is read.
471 .RB ( bash (1)
472 handles typeahead this way.)
473 [requires
474 .B _BSD_SOURCE
476 .BR _SVID_SOURCE ]
478 .B IEXTEN
479 Enable implementation-defined input processing.
480 This flag, as well as \fBICANON\fP must be enabled for the
481 special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted,
482 and for the \fBIUCLC\fP flag to be effective.
484 The \fIc_cc\fP array defines the terminal special characters.
485 The symbolic indices (initial values) and meaning are:
487 .B VDISCARD
488 (not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
489 Toggle: start/stop discarding pending output.
490 Recognized when
491 .B IEXTEN
492 is set, and then not passed as input.
494 .B VDSUSP
495 (not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
496 Delayed suspend character (DSUSP):
497 send
498 .B SIGTSTP
499 signal when the character is read by the user program.
500 Recognized when
501 .B IEXTEN
503 .B ISIG
504 are set, and the system supports
505 job control, and then not passed as input.
507 .B VEOF
508 (004, EOT, Ctrl-D)
509 End-of-file character (EOF).
510 More precisely: this character causes the pending tty buffer to be sent
511 to the waiting user program without waiting for end-of-line.
512 If it is the first character of the line, the
513 .BR read (2)
514 in the user program returns 0, which signifies end-of-file.
515 Recognized when
516 .B ICANON
517 is set, and then not passed as input.
519 .B VEOL
520 (0, NUL)
521 Additional end-of-line character (EOL).
522 Recognized when
523 .B ICANON
524 is set.
526 .B VEOL2
527 (not in POSIX; 0, NUL)
528 Yet another end-of-line character (EOL2).
529 Recognized when
530 .B ICANON
531 is set.
533 .B VERASE
534 (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #)
535 Erase character (ERASE).
536 This erases the previous not-yet-erased character,
537 but does not erase past EOF or beginning-of-line.
538 Recognized when
539 .B ICANON
540 is set, and then not passed as input.
542 .B VINTR
543 (003, ETX, Ctrl-C, or also 0177, DEL, rubout)
544 Interrupt character (INTR).
545 Send a
546 .B SIGINT
547 signal.
548 Recognized when
549 .B ISIG
550 is set, and then not passed as input.
552 .B VKILL
553 (025, NAK, Ctrl-U, or Ctrl-X, or also @)
554 Kill character (KILL).
555 This erases the input since the last EOF or beginning-of-line.
556 Recognized when
557 .B ICANON
558 is set, and then not passed as input.
560 .B VLNEXT
561 (not in POSIX; 026, SYN, Ctrl-V)
562 Literal next (LNEXT).
563 Quotes the next input character, depriving it of
564 a possible special meaning.
565 Recognized when
566 .B IEXTEN
567 is set, and then not passed as input.
569 .B VMIN
570 Minimum number of characters for noncanonical read (MIN).
572 .B VQUIT
573 (034, FS, Ctrl-\e)
574 Quit character (QUIT).
575 Send
576 .B SIGQUIT
577 signal.
578 Recognized when
579 .B ISIG
580 is set, and then not passed as input.
582 .B VREPRINT
583 (not in POSIX; 022, DC2, Ctrl-R)
584 Reprint unread characters (REPRINT).
585 Recognized when
586 .B ICANON
588 .B IEXTEN
589 are set, and then not passed as input.
591 .B VSTART
592 (021, DC1, Ctrl-Q)
593 Start character (START).
594 Restarts output stopped by the Stop character.
595 Recognized when
596 .B IXON
597 is set, and then not passed as input.
599 .B VSTATUS
600 (not in POSIX; not supported under Linux;
601 status request: 024, DC4, Ctrl-T).
602 Status character (STATUS).
603 Display status information at terminal,
604 including state of foreground process and amount of CPU time it has consumed.
605 Also sends a
606 .B SIGINFO
607 signal (not supported on Linux) to the foreground process group.
609 .B VSTOP
610 (023, DC3, Ctrl-S)
611 Stop character (STOP).
612 Stop output until Start character typed.
613 Recognized when
614 .B IXON
615 is set, and then not passed as input.
617 .B VSUSP
618 (032, SUB, Ctrl-Z)
619 Suspend character (SUSP).
620 Send
621 .B SIGTSTP
622 signal.
623 Recognized when
624 .B ISIG
625 is set, and then not passed as input.
627 .B VSWTCH
628 (not in POSIX; not supported under Linux; 0, NUL)
629 Switch character (SWTCH).
630 Used in System V to switch shells in
631 .IR "shell layers" ,
632 a predecessor to shell job control.
634 .B VTIME
635 Timeout in deciseconds for noncanonical read (TIME).
637 .B VWERASE
638 (not in POSIX; 027, ETB, Ctrl-W)
639 Word erase (WERASE).
640 Recognized when
641 .B ICANON
643 .B IEXTEN
644 are set, and then not passed as input.
646 An individual terminal special character can be disabled by setting
647 the value of the corresponding
648 .I c_cc
649 element to
650 .BR _POSIX_VDISABLE .
652 The above symbolic subscript values are all different, except that
653 .BR VTIME ,
654 .B VMIN
655 may have the same value as
656 .BR VEOL ,
657 .BR VEOF ,
658 respectively.
659 In noncanonical mode the special character meaning is replaced
660 by the timeout meaning.
661 For an explanation of
662 .B VMIN
664 .BR VTIME ,
665 see the description of
666 noncanonical mode below.
667 .SS Retrieving and changing terminal settings
668 .BR tcgetattr ()
669 gets the parameters associated with the object referred by \fIfd\fP and
670 stores them in the \fItermios\fP structure referenced by
671 \fItermios_p\fP.
672 This function may be invoked from a background process;
673 however, the terminal attributes may be subsequently changed by a
674 foreground process.
676 .BR tcsetattr ()
677 sets the parameters associated with the terminal (unless support is
678 required from the underlying hardware that is not available) from the
679 \fItermios\fP structure referred to by \fItermios_p\fP.
680 \fIoptional_actions\fP specifies when the changes take effect:
681 .IP \fBTCSANOW\fP
682 the change occurs immediately.
683 .IP \fBTCSADRAIN\fP
684 the change occurs after all output written to
685 .I fd
686 has been transmitted.
687 This option should be used when changing
688 parameters that affect output.
689 .IP \fBTCSAFLUSH\fP
690 the change occurs after all output written to the object referred by
691 .I fd
692 has been transmitted, and all input that has been received but not read
693 will be discarded before the change is made.
694 .SS Canonical and noncanonical mode
695 The setting of the
696 .B ICANON
697 canon flag in
698 .I c_lflag
699 determines whether the terminal is operating in canonical mode
700 .RB ( ICANON
701 set) or
702 noncanonical mode
703 .RB ( ICANON
704 unset).
705 By default,
706 .B ICANON
707 is set.
709 In canonical mode:
710 .IP * 2
711 Input is made available line by line.
712 An input line is available when one of the line delimiters
713 is typed (NL, EOL, EOL2; or EOF at the start of line).
714 Except in the case of EOF, the line delimiter is included
715 in the buffer returned by
716 .BR read (2).
717 .IP * 2
718 Line editing is enabled (ERASE, KILL;
719 and if the
720 .B IEXTEN
721 flag is set: WERASE, REPRINT, LNEXT).
723 .BR read (2)
724 returns at most one line of input; if the
725 .BR read (2)
726 requested fewer bytes than are available in the current line of input,
727 then only as many bytes as requested are read,
728 and the remaining characters will be available for a future
729 .BR read (2).
730 .IP * 2
731 The maximum line length is 4096 chars
732 (including the terminating newline character);
733 lines longer than 4096 chars are truncated.
734 After 4095 characters, input processing (e.g.,
735 .B ISIG
737 .B ECHO*
738 processing) continues, but any input data after 4095 characters up to
739 (but not including) any terminating newline is discarded.
740 This ensures that the terminal can always receive
741 more input until at least one line can be read.
743 In noncanonical mode input is available immediately (without
744 the user having to type a line-delimiter character),
745 no input processing is performed,
746 and line editing is disabled.
747 The read buffer will only accept 4095 chars; this provides the
748 necessary space for a newline char if the input mode is switched
749 to canonical.
750 The settings of MIN
751 .RI ( c_cc[VMIN] )
752 and TIME
753 .RI ( c_cc[VTIME] )
754 determine the circumstances in which a
755 .BR read (2)
756 completes; there are four distinct cases:
758 MIN == 0, TIME == 0 (polling read)
759 If data is available,
760 .BR read (2)
761 returns immediately, with the lesser of the number of bytes
762 available, or the number of bytes requested.
763 If no data is available,
764 .BR read (2)
765 returns 0.
767 MIN > 0, TIME == 0 (blocking read)
768 .BR read (2)
769 blocks until MIN bytes are available,
770 and returns up to the number of bytes requested.
772 MIN == 0, TIME > 0 (read with timeout)
773 TIME specifies the limit for a timer in tenths of a second.
774 The timer is started when
775 .BR read (2)
776 is called.
777 .BR read (2)
778 returns either when at least one byte of data is available,
779 or when the timer expires.
780 If the timer expires without any input becoming available,
781 .BR read (2)
782 returns 0.
783 If data is already available at the time of the call to
784 .BR read (2),
785 the call behaves as though the data was received immediately after the call.
787 MIN > 0, TIME > 0 (read with interbyte timeout)
788 TIME specifies the limit for a timer in tenths of a second.
789 Once an initial byte of input becomes available,
790 the timer is restarted after each further byte is received.
791 .BR read (2)
792 returns when any of the following conditions is met:
794 .IP * 3
795 MIN bytes have been received.
796 .IP *
797 The interbyte timer expires.
798 .IP *
799 The number of bytes requested by
800 .BR read (2)
801 has been received.
802 (POSIX does not specify this termination condition,
803 and on some other implementations
804 .\" e.g., Solaris
805 .BR read (2)
806 does not return in this case.)
809 Because the timer is started only after the initial byte
810 becomes available, at least one byte will be read.
811 If data is already available at the time of the call to
812 .BR read (2),
813 the call behaves as though the data was received immediately after the call.
815 POSIX
816 .\" POSIX.1-2008 XBD 11.1.7
817 does not specify whether the setting of the
818 .B O_NONBLOCK
819 file status flag takes precedence over the MIN and TIME settings.
821 .B O_NONBLOCK
822 is set, a
823 .BR read (2)
824 in noncanonical mode may return immediately,
825 regardless of the setting of MIN or TIME.
826 Furthermore, if no data is available,
827 POSIX permits a
828 .BR read (2)
829 in noncanonical mode to return either 0, or \-1 with
830 .I errno
831 set to
832 .BR EAGAIN .
833 .SS Raw mode
834 .BR cfmakeraw ()
835 sets the terminal to something like the
836 "raw" mode of the old Version 7 terminal driver:
837 input is available character by character,
838 echoing is disabled, and all special processing of
839 terminal input and output characters is disabled.
840 The terminal attributes are set as follows:
842 .in +4n
844 termios_p\->c_iflag &= \(ti(IGNBRK | BRKINT | PARMRK | ISTRIP
845                 | INLCR | IGNCR | ICRNL | IXON);
846 termios_p\->c_oflag &= \(tiOPOST;
847 termios_p\->c_lflag &= \(ti(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
848 termios_p\->c_cflag &= \(ti(CSIZE | PARENB);
849 termios_p\->c_cflag |= CS8;
853 .SS Line control
854 .BR tcsendbreak ()
855 transmits a continuous stream of zero-valued bits for a specific
856 duration, if the terminal is using asynchronous serial data
857 transmission.
858 If \fIduration\fP is zero, it transmits zero-valued bits
859 for at least 0.25 seconds, and not more than 0.5 seconds.
860 If \fIduration\fP is not zero, it sends zero-valued bits for some
861 implementation-defined length of time.
863 If the terminal is not using asynchronous serial data transmission,
864 .BR tcsendbreak ()
865 returns without taking any action.
867 .BR tcdrain ()
868 waits until all output written to the object referred to by
869 .I fd
870 has been transmitted.
872 .BR tcflush ()
873 discards data written to the object referred to by
874 .I fd
875 but not transmitted, or data received but not read, depending on the
876 value of
877 .IR queue_selector :
878 .IP \fBTCIFLUSH\fP
879 flushes data received but not read.
880 .IP \fBTCOFLUSH\fP
881 flushes data written but not transmitted.
882 .IP \fBTCIOFLUSH\fP
883 flushes both data received but not read, and data written but not
884 transmitted.
886 .BR tcflow ()
887 suspends transmission or reception of data on the object referred to by
888 .IR fd ,
889 depending on the value of
890 .IR action :
891 .IP \fBTCOOFF\fP
892 suspends output.
893 .IP \fBTCOON\fP
894 restarts suspended output.
895 .IP \fBTCIOFF\fP
896 transmits a STOP character, which stops the terminal device from
897 transmitting data to the system.
898 .IP \fBTCION\fP
899 transmits a START character, which starts the terminal device
900 transmitting data to the system.
902 The default on open of a terminal file is that neither its input nor its
903 output is suspended.
904 .SS Line speed
905 The baud rate functions are provided for getting and setting the values
906 of the input and output baud rates in the \fItermios\fP structure.
907 The new values do not take effect
908 until
909 .BR tcsetattr ()
910 is successfully called.
912 Setting the speed to \fBB0\fP instructs the modem to "hang up".
913 The actual bit rate corresponding to \fBB38400\fP may be altered with
914 .BR setserial (8).
916 The input and output baud rates are stored in the \fItermios\fP
917 structure.
919 .BR cfgetospeed ()
920 returns the output baud rate stored in the \fItermios\fP structure
921 pointed to by
922 .IR termios_p .
924 .BR cfsetospeed ()
925 sets the output baud rate stored in the \fItermios\fP structure pointed
926 to by \fItermios_p\fP to \fIspeed\fP, which must be one of these constants:
929 .ft B
930         B0
931         B50
932         B75
933         B110
934         B134
935         B150
936         B200
937         B300
938         B600
939         B1200
940         B1800
941         B2400
942         B4800
943         B9600
944         B19200
945         B38400
946         B57600
947         B115200
948         B230400
949         B460800
950         B500000
951         B576000
952         B921600
953         B1000000
954         B1152000
955         B1500000
956         B2000000
957 .ft P
960 These constants are additionally supported on the SPARC architecture:
963 .ft B
964         B76800
965         B153600
966         B307200
967         B614400
968 .ft P
971 These constants are additionally supported on non-SPARC architectures:
974 .ft B
975         B2500000
976         B3000000
977         B3500000
978         B4000000
979 .ft P
982 Due to differences between architectures, portable applications should check
983 if a particular
984 .BI B nnn
985 constant is defined prior to using it.
987 The zero baud rate,
988 .BR B0 ,
989 is used to terminate the connection.
990 If B0 is specified, the modem control lines shall no longer be asserted.
991 Normally, this will disconnect the line.
992 .B CBAUDEX
993 is a mask
994 for the speeds beyond those defined in POSIX.1 (57600 and above).
995 Thus,
996 .BR B57600 " & " CBAUDEX
997 is nonzero.
999 Setting the baud rate to a value other than those defined by
1000 .BI B nnn
1001 constants is possible via the
1002 .B TCSETS2
1003 ioctl; see
1004 .BR ioctl_tty (2).
1006 .BR cfgetispeed ()
1007 returns the input baud rate stored in the
1008 .I termios
1009 structure.
1011 .BR cfsetispeed ()
1012 sets the input baud rate stored in the
1013 .I termios
1014 structure to
1015 .IR speed ,
1016 which must be specified as one of the
1017 .BI B nnn
1018 constants listed above for
1019 .BR cfsetospeed ().
1020 If the input baud rate is set to zero, the input baud rate will be
1021 equal to the output baud rate.
1023 .BR cfsetspeed ()
1024 is a 4.4BSD extension.
1025 It takes the same arguments as
1026 .BR cfsetispeed (),
1027 and sets both input and output speed.
1028 .SH RETURN VALUE
1029 .BR cfgetispeed ()
1030 returns the input baud rate stored in the
1031 \fItermios\fP
1032 structure.
1034 .BR cfgetospeed ()
1035 returns the output baud rate stored in the \fItermios\fP structure.
1037 All other functions return:
1038 .IP 0
1039 on success.
1040 .IP \-1
1041 on failure and set
1042 .I errno
1043 to indicate the error.
1045 Note that
1046 .BR tcsetattr ()
1047 returns success if \fIany\fP of the requested changes could be
1048 successfully carried out.
1049 Therefore, when making multiple changes
1050 it may be necessary to follow this call with a further call to
1051 .BR tcgetattr ()
1052 to check that all changes have been performed successfully.
1053 .SH ATTRIBUTES
1054 For an explanation of the terms used in this section, see
1055 .BR attributes (7).
1057 .ad l
1060 allbox;
1061 lbx lb lb
1062 l l l.
1063 Interface       Attribute       Value
1065 .BR tcgetattr (),
1066 .BR tcsetattr (),
1067 .BR tcdrain (),
1068 .BR tcflush (),
1069 .BR tcflow (),
1070 .BR tcsendbreak (),
1071 .BR cfmakeraw (),
1072 .BR cfgetispeed (),
1073 .BR cfgetospeed (),
1074 .BR cfsetispeed (),
1075 .BR cfsetospeed (),
1076 .BR cfsetspeed ()
1077 T}      Thread safety   MT-Safe
1081 .sp 1
1082 .\" FIXME: The markings are different from that in the glibc manual.
1083 .\" markings in glibc manual are more detailed:
1085 .\"     tcsendbreak: MT-Unsafe race:tcattr(filedes)/bsd
1086 .\"     tcflow: MT-Unsafe race:tcattr(filedes)/bsd
1088 .\" glibc manual says /bsd indicate the preceding marker only applies
1089 .\" when the underlying kernel is a BSD kernel.
1090 .\" So, it is safety in Linux kernel.
1092 .SH CONFORMING TO
1093 .BR tcgetattr (),
1094 .BR tcsetattr (),
1095 .BR tcsendbreak (),
1096 .BR tcdrain (),
1097 .BR tcflush (),
1098 .BR tcflow (),
1099 .BR cfgetispeed (),
1100 .BR cfgetospeed (),
1101 .BR cfsetispeed (),
1103 .BR cfsetospeed ()
1104 are specified in POSIX.1-2001.
1106 .BR cfmakeraw ()
1108 .BR cfsetspeed ()
1109 are nonstandard, but available on the BSDs.
1110 .SH NOTES
1111 UNIX\ V7 and several later systems have a list of baud rates
1112 where after the values
1113 .BR B0
1114 through
1115 .B B9600
1116 one finds the two constants
1117 .BR EXTA ,
1118 .B EXTB
1119 ("External A" and "External B").
1120 Many systems extend the list with much higher baud rates.
1122 The effect of a nonzero \fIduration\fP with
1123 .BR tcsendbreak ()
1124 varies.
1125 SunOS specifies a break of
1126 .I "duration\ *\ N"
1127 seconds, where \fIN\fP is at least 0.25, and not more than 0.5.
1128 Linux, AIX, DU, Tru64 send a break of
1129 .I duration
1130 milliseconds.
1131 FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
1132 .IR duration .
1133 Under Solaris and UnixWare,
1134 .BR tcsendbreak ()
1135 with nonzero
1136 .I duration
1137 behaves like
1138 .BR tcdrain ().
1139 .\" libc4 until 4.7.5, glibc for sysv: EINVAL for duration > 0.
1140 .\" libc4.7.6, libc5, glibc for unix: duration in ms.
1141 .\" glibc for bsd: duration in us
1142 .\" glibc for sunos4: ignore duration
1143 .SH BUGS
1144 .\" kernel 77e5bff1640432f28794a00800955e646dcd7455
1145 .\" glibc 573963e32ffac46d9891970ddebde2ac3212c5c0
1146 On the Alpha architecture before Linux 4.16 (and glibc before 2.28), the
1147 .B XTABS
1148 value was different from
1149 .B TAB3
1150 and it was ignored by the
1151 .B N_TTY
1152 line discipline code of the terminal driver as a result
1153 (because as it wasn't part of the
1154 .B TABDLY
1155 mask).
1156 .SH SEE ALSO
1157 .BR reset (1),
1158 .BR setterm (1),
1159 .BR stty (1),
1160 .BR tput (1),
1161 .BR tset (1),
1162 .BR tty (1),
1163 .BR ioctl_console (2),
1164 .BR ioctl_tty (2),
1165 .BR setserial (8)