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