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