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