OSDN Git Service

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