OSDN Git Service

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