]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/termios.3
Fix capitalisations
[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
34.\"
35.TH TERMIOS 3 2004-10-31 "Linux" "Linux Programmer's Manual"
36.SH NAME
37termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
38cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed \-
39get and set terminal attributes, line control, get and set baud rate
40.SH SYNOPSIS
41.ad l
42.ft B
43#include <termios.h>
44.br
45#include <unistd.h>
46.sp
47.BI "int tcgetattr(int " fd ", struct termios *" termios_p );
48.sp
49.BI "int tcsetattr(int " fd ", int " optional_actions ", const struct termios *" termios_p );
50.sp
51.BI "int tcsendbreak(int " fd ", int " duration );
52.sp
53.BI "int tcdrain(int " fd );
54.sp
55.BI "int tcflush(int " fd ", int " queue_selector );
56.sp
57.BI "int tcflow(int " fd ", int " action );
58.sp
59.BI "void cfmakeraw(struct termios *" termios_p );
60.sp
61.BI "speed_t cfgetispeed(const struct termios *" termios_p );
62.sp
63.BI "speed_t cfgetospeed(const struct termios *" termios_p );
64.sp
65.BI "int cfsetispeed(struct termios *" termios_p ", speed_t " speed );
66.sp
67.BI "int cfsetospeed(struct termios *" termios_p ", speed_t " speed );
68.ft P
69.ad b
70.SH DESCRIPTION
71The termios functions describe a general terminal interface that is
72provided to control asynchronous communications ports.
73.LP
74Many of the functions described here have a \fItermios_p\fP argument
75that is a pointer to a \fBtermios\fP structure. This structure contains
76at least the following members:
77.ne 9
78.sp
79.RS
80.nf
81tcflag_t \fIc_iflag\fP; /* input modes */
82tcflag_t \fIc_oflag\fP; /* output modes */
83tcflag_t \fIc_cflag\fP; /* control modes */
84tcflag_t \fIc_lflag\fP; /* local modes */
85cc_t \fIc_cc\fP[\fBNCCS\fP]; /* control chars */
86.fi
87.RE
88.PP
89\fIc_iflag\fP flag constants:
90.TP
91.B IGNBRK
92Ignore BREAK condition on input.
93.TP
94.B BRKINT
95If \fBIGNBRK\fP is set, a BREAK is ignored. If it is not set
96but \fBBRKINT\fP is set, then a BREAK causes the input and output
97queues to be flushed, and if the terminal is the controlling
98terminal of a foreground process group, it will cause a
99\fBSIGINT\fP to be sent to this foreground process group.
100When neither \fBIGNBRK\fP nor \fBBRKINT\fP are set, a BREAK
101reads as a NUL character, except when \fBPARMRK\fP is set,
102in which case it reads as the sequence \\377 \\0 \\0.
103.TP
104.B IGNPAR
105Ignore framing errors and parity errors.
106.TP
107.B PARMRK
108If \fBIGNPAR\fP is not set, prefix a character with a parity error or
109framing error with \\377 \\0. If neither \fBIGNPAR\fP nor \fBPARMRK\fP
110is set, read a character with a parity error or framing error
111as \\0.
112.TP
113.B INPCK
114Enable input parity checking.
115.TP
116.B ISTRIP
117Strip off eighth bit.
118.TP
119.B INLCR
120Translate NL to CR on input.
121.TP
122.B IGNCR
123Ignore carriage return on input.
124.TP
125.B ICRNL
126Translate carriage return to newline on input (unless \fBIGNCR\fP is set).
127.TP
128.B IUCLC
129(not in POSIX) Map uppercase characters to lowercase on input.
130.TP
131.B IXON
132Enable XON/XOFF flow control on output.
133.TP
134.B IXANY
135(not in POSIX.1; XSI) Enable any character to restart output.
136.TP
137.B IXOFF
138Enable XON/XOFF flow control on input.
139.TP
140.B IMAXBEL
141(not in POSIX) Ring bell when input queue is full.
142Linux does not implement this bit, and acts as if it is always set.
143.PP
144\fIc_oflag\fP flag constants defined in POSIX.1:
145.TP
146.B OPOST
147Enable implementation-defined output processing.
148.PP
149The remaining \fIc_oflag\fP flag constants are defined in POSIX 1003.1-2001,
150unless marked otherwise.
151.TP
152.B OLCUC
153(not in POSIX) Map lowercase characters to uppercase on output.
154.TP
155.B ONLCR
156(XSI) Map NL to CR-NL on output.
157.TP
158.B OCRNL
159Map CR to NL on output.
160.TP
161.B ONOCR
162Don't output CR at column 0.
163.TP
164.B ONLRET
165Don't output CR.
166.TP
167.B OFILL
168Send fill characters for a delay, rather than using a timed delay.
169.TP
170.B OFDEL
171(not in POSIX) Fill character is ASCII DEL (0177).
172If unset, fill character is ASCII NUL.
173.TP
174.B NLDLY
175Newline delay mask. Values are \fBNL0\fP and \fBNL1\fP.
176.TP
177.B CRDLY
178Carriage return delay mask.
179Values are \fBCR0\fP, \fBCR1\fP, \fBCR2\fP, or \fBCR3\fP.
180.TP
181.B TABDLY
182Horizontal tab delay mask.
183Values are \fBTAB0\fP, \fBTAB1\fP, \fBTAB2\fP, \fBTAB3\fP (or \fBXTABS\fP).
184A value of TAB3, that is, XTABS, expands tabs to spaces
185(with tab stops every eight columns).
186.TP
187.B BSDLY
188Backspace delay mask. Values are \fBBS0\fP or \fBBS1\fP.
189(Has never been implemented.)
190.TP
191.B VTDLY
192Vertical tab delay mask. Values are \fBVT0\fP or \fBVT1\fP.
193.TP
194.B FFDLY
195Form feed delay mask. Values are \fBFF0\fP or \fBFF1\fP.
196.PP
197\fIc_cflag\fP flag constants:
198.TP
199.B CBAUD
200(not in POSIX) Baud speed mask (4+1 bits).
201.TP
202.B CBAUDEX
203(not in POSIX) Extra baud speed mask (1 bit), included in CBAUD.
204.LP
205(POSIX says that the baud speed is stored in the termios structure
206without specifying where precisely, and provides
63aa9df0 207.BR cfgetispeed ()
fea681da 208and
63aa9df0 209.BR cfsetispeed ()
fea681da
MK
210for getting at it. Some systems use bits selected by CBAUD in
211.IR c_cflag ,
212other systems use separate fields, e.g.
213.I sg_ispeed
214and
215.IR sg_ospeed .)
216.TP
217.B CSIZE
218Character size mask.
219Values are \fBCS5\fP, \fBCS6\fP, \fBCS7\fP, or \fBCS8\fP.
220.TP
221.B CSTOPB
222Set two stop bits, rather than one.
223.TP
224.B CREAD
225Enable receiver.
226.TP
227.B PARENB
228Enable parity generation on output and parity checking for input.
229.TP
230.B PARODD
231Parity for input and output is odd.
232.TP
233.B HUPCL
234Lower modem control lines after last process closes the device (hang up).
235.TP
236.B CLOCAL
237Ignore modem control lines.
238.TP
239.B LOBLK
240(not in POSIX) Block output from a noncurrent shell layer.
241(For use by \fBshl\fP.)
242.TP
243.B CIBAUD
244(not in POSIX) Mask for input speeds. The values for the CIBAUD bits are
245the same as the values for the CBAUD bits, shifted left IBSHIFT bits.
246.TP
247.B CRTSCTS
248(not in POSIX) Enable RTS/CTS (hardware) flow control.
249.PP
250\fIc_lflag\fP flag constants:
251.TP
252.B ISIG
253When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
254generate the corresponding signal.
255.TP
256.B ICANON
257Enable canonical mode. This enables the special characters
258EOF, EOL, EOL2, ERASE, KILL, LNEXT, REPRINT, STATUS, and WERASE, and
259buffers by lines.
260.TP
261.B XCASE
262(not in POSIX; not supported under Linux)
263If \fBICANON\fP is also set, terminal is uppercase only.
264Input is converted to lowercase, except for characters preceded by \\.
265On output, uppercase characters are preceded by \\ and lowercase
266characters are converted to uppercase.
267.TP
268.B ECHO
269Echo input characters.
270.TP
271.B ECHOE
272If \fBICANON\fP is also set, the ERASE character erases the preceding
273input character, and WERASE erases the preceding word.
274.TP
275.B ECHOK
276If \fBICANON\fP is also set, the KILL character erases the current line.
277.TP
278.B ECHONL
279If \fBICANON\fP is also set, echo the NL character even if ECHO is not set.
280.TP
281.B ECHOCTL
282(not in POSIX) If \fBECHO\fP is also set, ASCII control signals other than
283TAB, NL, START, and STOP are echoed as ^X, where X is the character with
284ASCII code 0x40 greater than the control signal. For example, character
2850x08 (BS) is echoed as ^H.
286.TP
287.B ECHOPRT
288(not in POSIX) If \fBICANON\fP and \fBIECHO\fP are also set, characters
289are printed as they are being erased.
290.TP
291.B ECHOKE
292(not in POSIX) If \fBICANON\fP is also set, KILL is echoed by erasing
293each character on the line, as specified by \fBECHOE\fP and \fBECHOPRT\fP.
294.TP
295.B DEFECHO
296(not in POSIX) Echo only when a process is reading.
297.TP
298.B FLUSHO
299(not in POSIX; not supported under Linux)
300Output is being flushed. This flag is toggled by typing
301the DISCARD character.
302.TP
303.B NOFLSH
304Disable flushing the input and output queues when generating the SIGINT,
305SIGQUIT and SIGSUSP signals.
306.\" Stevens lets SIGSUSP only flush the input queue
307.TP
308.B TOSTOP
309Send the SIGTTOU signal to the process group of a background process
310which tries to write to its controlling terminal.
311.TP
312.B PENDIN
313(not in POSIX; not supported under Linux)
314All characters in the input queue are reprinted when
315the next character is read. (\fBbash\fP handles typeahead this way.)
316.TP
317.B IEXTEN
318Enable implementation-defined input processing.
319This flag, as well as \fBICANON\fP must be enabled for the
320special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted,
321and for the \fBIUCLC\fP flag to be effective.
322.PP
323The \fIc_cc\fP array defines the special control characters.
324The symbolic indices (initial values) and meaning are:
325.TP
326.B VINTR
327(003, ETX, Ctrl-C, or also 0177, DEL, rubout)
328Interrupt character. Send a SIGINT signal.
329Recognized when ISIG is set, and then not passed as input.
330.TP
331.B VQUIT
332(034, FS, Ctrl-\e)
333Quit character. Send SIGQUIT signal.
334Recognized when ISIG is set, and then not passed as input.
335.TP
336.B VERASE
337(0177, DEL, rubout, or 010, BS, Ctrl-H, or also #)
338Erase character. This erases the previous not-yet-erased character,
339but does not erase past EOF or beginning-of-line.
340Recognized when ICANON is set, and then not passed as input.
341.TP
342.B VKILL
343(025, NAK, Ctrl-U, or Ctrl-X, or also @)
344Kill character. This erases the input since the last EOF or beginning-of-line.
345Recognized when ICANON is set, and then not passed as input.
346.TP
347.B VEOF
348(004, EOT, Ctrl-D)
349End-of-file character.
350More precisely: this character causes the pending tty buffer to be sent
351to the waiting user program without waiting for end-of-line.
63aa9df0 352If it is the first character of the line, the \fIread\fP() in the
fea681da
MK
353user program returns 0, which signifies end-of-file.
354Recognized when ICANON is set, and then not passed as input.
355.TP
356.B VMIN
357Minimum number of characters for non-canonical read.
358.TP
359.B VEOL
360(0, NUL)
361Additional end-of-line character.
362Recognized when ICANON is set.
363.TP
364.B VTIME
365Timeout in deciseconds for non-canonical read.
366.TP
367.B VEOL2
368(not in POSIX; 0, NUL)
369Yet another end-of-line character.
370Recognized when ICANON is set.
371.TP
372.B VSWTCH
373(not in POSIX; not supported under Linux; 0, NUL)
374Switch character. (Used by \fBshl\fP only.)
375.TP
376.B VSTART
377(021, DC1, Ctrl-Q)
378Start character. Restarts output stopped by the Stop character.
379Recognized when IXON is set, and then not passed as input.
380.TP
381.B VSTOP
382(023, DC3, Ctrl-S)
383Stop character. Stop output until Start character typed.
384Recognized when IXON is set, and then not passed as input.
385.TP
386.B VSUSP
387(032, SUB, Ctrl-Z)
388Suspend character. Send SIGTSTP signal.
389Recognized when ISIG is set, and then not passed as input.
390.TP
391.B VDSUSP
392(not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
393Delayed suspend character:
394send SIGTSTP signal when the character is read by the user program.
395Recognized when IEXTEN and ISIG are set, and the system supports
396job control, and then not passed as input.
397.TP
398.B VLNEXT
399(not in POSIX; 026, SYN, Ctrl-V)
400Literal next. Quotes the next input character, depriving it of
401a possible special meaning.
402Recognized when IEXTEN is set, and then not passed as input.
403.TP
404.B VWERASE
405(not in POSIX; 027, ETB, Ctrl-W)
406Word erase.
407Recognized when ICANON and IEXTEN are set, and then not passed as input.
408.TP
409.B VREPRINT
410(not in POSIX; 022, DC2, Ctrl-R)
411Reprint unread characters.
412Recognized when ICANON and IEXTEN are set, and then not passed as input.
413.TP
414.B VDISCARD
415(not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
416Toggle: start/stop discarding pending output.
417Recognized when IEXTEN is set, and then not passed as input.
418.TP
419.B VSTATUS
420(not in POSIX; not supported under Linux;
421status request: 024, DC4, Ctrl-T).
422.LP
423These symbolic subscript values are all different, except that
424VTIME, VMIN may have the same value as VEOL, VEOF, respectively.
425(In non-canonical mode the special character meaning is replaced
426by the timeout meaning. MIN represents the minimum number of characters
427that should be received to satisfy the read. TIME is a decisecond-valued
428timer. When both are set, a read will wait until at least one character
429has been received, and then return as soon as either MIN characters
430have been received or time TIME has passed since the last character
431was received. If only MIN is set, the read will not return before
432MIN characters have been received. If only TIME is set, the read will
433return as soon as either at least one character has been received,
434or the timer times out. If neither is set, the read will return
435immediately, only giving the currently already available characters.)
436.PP
63aa9df0 437.BR tcgetattr ()
fea681da
MK
438gets the parameters associated with the object referred by \fIfd\fP and
439stores them in the \fBtermios\fP structure referenced by
440\fItermios_p\fP. This function may be invoked from a background process;
441however, the terminal attributes may be subsequently changed by a
442foreground process.
443.LP
63aa9df0 444.BR tcsetattr ()
fea681da
MK
445sets the parameters associated with the terminal (unless support is
446required from the underlying hardware that is not available) from the
447\fBtermios\fP structure referred to by \fItermios_p\fP.
448\fIoptional_actions\fP specifies when the changes take effect:
449.IP \fBTCSANOW\fP
450the change occurs immediately.
451.IP \fBTCSADRAIN\fP
452the change occurs after all output written to
453.I fd
454has been transmitted. This function should be used when changing
455parameters that affect output.
456.IP \fBTCSAFLUSH\fP
457the change occurs after all output written to the object referred by
458.I fd
459has been transmitted, and all input that has been received but not read
460will be discarded before the change is made.
461.LP
63aa9df0 462.BR tcsendbreak ()
fea681da
MK
463transmits a continuous stream of zero-valued bits for a specific
464duration, if the terminal is using asynchronous serial data
465transmission. If \fIduration\fP is zero, it transmits zero-valued bits
466for at least 0.25 seconds, and not more that 0.5 seconds. If
467\fIduration\fP is not zero, it sends zero-valued bits for some
468implementation-defined length of time.
469.LP
470If the terminal is not using asynchronous serial data transmission,
63aa9df0 471\fBtcsendbreak\fP() returns without taking any action.
fea681da 472.LP
63aa9df0 473.BR tcdrain ()
fea681da
MK
474waits until all output written to the object referred to by
475.I fd
476has been transmitted.
477.LP
63aa9df0 478.BR tcflush ()
fea681da
MK
479discards data written to the object referred to by
480.I fd
481but not transmitted, or data received but not read, depending on the
482value of
483.IR queue_selector :
484.IP \fBTCIFLUSH\fP
485flushes data received but not read.
486.IP \fBTCOFLUSH\fP
487flushes data written but not transmitted.
488.IP \fBTCIOFLUSH\fP
489flushes both data received but not read, and data written but not
490transmitted.
491.LP
63aa9df0 492.BR tcflow ()
fea681da
MK
493suspends transmission or reception of data on the object referred to by
494.IR fd ,
495depending on the value of
496.IR action :
497.IP \fBTCOOFF\fP
498suspends output.
499.IP \fBTCOON\fP
500restarts suspended output.
501.IP \fBTCIOFF\fP
502transmits a STOP character, which stops the terminal device from transmitting data to the
503system.
504.IP \fBTCION\fP
505transmits a START character, which starts the terminal device transmitting data to the
506system.
507.LP
508The default on open of a terminal file is that neither its input nor its
509output is suspended.
510.LP
511The baud rate functions are provided for getting and setting the values
512of the input and output baud rates in the \fBtermios\fP structure. The
513new values do not take effect
63aa9df0 514until \fBtcsetattr\fP() is successfully called.
fea681da
MK
515
516Setting the speed to \fBB0\fP instructs the modem to "hang up".
517The actual bit rate corresponding to \fBB38400\fP may be altered with
518\fBsetserial\fP(8).
519.LP
520The input and output baud rates are stored in the \fBtermios\fP
521structure.
522.LP
e511ffb6 523\fBcfmakeraw\fP() sets the terminal attributes as follows:
fea681da
MK
524.nf
525 termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
526 |INLCR|IGNCR|ICRNL|IXON);
527 termios_p->c_oflag &= ~OPOST;
528 termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
529 termios_p->c_cflag &= ~(CSIZE|PARENB);
530 termios_p->c_cflag |= CS8;
531.fi
532.LP
63aa9df0 533.BR cfgetospeed ()
fea681da
MK
534returns the output baud rate stored in the \fBtermios\fP structure
535pointed to by
536.IR termios_p .
537.LP
63aa9df0 538.BR cfsetospeed ()
fea681da
MK
539sets the output baud rate stored in the \fBtermios\fP structure pointed
540to by \fItermios_p\fP to \fIspeed\fP, which must be one of these constants:
541.nf
542.ft B
543 B0
544 B50
545 B75
546 B110
547 B134
548 B150
549 B200
550 B300
551 B600
552 B1200
553 B1800
554 B2400
555 B4800
556 B9600
557 B19200
558 B38400
559 B57600
560 B115200
561 B230400
562.ft P
563.fi
564The zero baud rate, \fBB0\fP,
565is used to terminate the connection. If B0
566is specified, the modem control lines shall no longer be asserted.
567Normally, this will disconnect the line. \fBCBAUDEX\fP is a mask
568for the speeds beyond those defined in POSIX.1 (57600 and above).
f59a3f19 569Thus, \fBB57600\fP & \fBCBAUDEX\fP is non-zero.
fea681da 570.LP
63aa9df0 571.BR cfgetispeed ()
fea681da
MK
572returns the input baud rate stored in the \fBtermios\fP structure.
573.LP
63aa9df0 574.BR cfsetispeed ()
fea681da
MK
575sets the input baud rate stored in the \fBtermios\fP structure to
576.IR speed .
577If the input baud rate is set to zero, the input baud rate will be
578equal to the output baud rate.
579.LP
63aa9df0 580.BR cfsetspeed ()
fea681da
MK
581is a 4.4 BSD extension. It will set both input and output speed.
582.SH "RETURN VALUE"
583.LP
63aa9df0 584.BR cfgetispeed ()
fea681da
MK
585returns the input baud rate stored in the
586\fBtermios\fP
587structure.
588.LP
63aa9df0 589.BR cfgetospeed ()
fea681da
MK
590returns the output baud rate stored in the \fBtermios\fP structure.
591.LP
592All other functions return:
593.IP 0
594on success.
595.IP \-1
596on failure and set
597.I errno
598to indicate the error.
599.LP
600Note that
63aa9df0 601.BI tcsetattr ()
fea681da
MK
602returns success if \fIany\fP of the requested changes could be
603successfully carried out. Therefore, when making multiple changes
604it may be necessary to follow this call with a further call to
63aa9df0 605.BI tcgetattr ()
fea681da
MK
606to check that all changes have been performed successfully.
607
608.SH NOTES
609Unix V7 and several later systems have a list of baud rates
610where after the fourteen values B0, ..., B9600 one finds the
611two constants EXTA, EXTB ("External A" and "External B").
612Many systems extend the list with much higher baud rates.
613.LP
e511ffb6 614The effect of a non-zero \fIduration\fP with \fBtcsendbreak\fP() varies.
fea681da
MK
615SunOS specifies a break of
616.IB duration * N
617seconds, where \fIN\fP is at least 0.25, and not more than 0.5.
618Linux, AIX, DU, Tru64 send a break of
619.I duration
620milliseconds.
621FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
622.IR duration .
623Under Solaris and Unixware,
e511ffb6 624.BR tcsendbreak ()
f59a3f19 625with non-zero
fea681da
MK
626.I duration
627behaves like
e511ffb6 628.BR tcdrain ().
fea681da
MK
629.\" libc4 until 4.7.5, glibc for sysv: EINVAL for duration > 0.
630.\" libc4.7.6, libc5, glibc for unix: duration in ms.
631.\" glibc for bsd: duration in us
632.\" glibc for sunos4: ignore duration
633.SH "SEE ALSO"
634.BR stty (1),
635.BR setserial (8)