]>
Commit | Line | Data |
---|---|---|
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 | |
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 | |
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 |
76 | The termios functions describe a general terminal interface that is | |
77 | provided to control asynchronous communications ports. | |
87d1fd87 | 78 | .SS "The termios structure" |
fea681da MK |
79 | .LP |
80 | Many of the functions described here have a \fItermios_p\fP argument | |
c13182ef MK |
81 | that is a pointer to a \fItermios\fP structure. |
82 | This structure contains at least the following members: | |
fea681da MK |
83 | .ne 9 |
84 | .sp | |
85 | .RS | |
86 | .nf | |
87 | tcflag_t \fIc_iflag\fP; /* input modes */ | |
88 | tcflag_t \fIc_oflag\fP; /* output modes */ | |
89 | tcflag_t \fIc_cflag\fP; /* control modes */ | |
90 | tcflag_t \fIc_lflag\fP; /* local modes */ | |
869ebe5b | 91 | cc_t \fIc_cc\fP[\fBNCCS\fP]; /* control chars */ |
fea681da MK |
92 | .fi |
93 | .RE | |
94 | .PP | |
869ebe5b | 95 | The values that may be assigned to these fields are described below. |
c13182ef MK |
96 | In the case of the first four bit-mask fields, |
97 | the definitions of some of the associated flags that may be set are | |
869ebe5b | 98 | only exposed if a specific feature test macro (see |
a8e7c990 | 99 | .BR feature_test_macros (7)) |
869ebe5b MK |
100 | is defined, as noted in brackets ("[]"). |
101 | .PP | |
42b09930 | 102 | In the descriptions below, "not in POSIX" means that the |
c13182ef MK |
103 | value is not specified in POSIX.1-2001, |
104 | and "XSI" means that the value is specified in POSIX.1-2001 | |
42b09930 MK |
105 | as part of the XSI extension. |
106 | .PP | |
fea681da MK |
107 | \fIc_iflag\fP flag constants: |
108 | .TP | |
109 | .B IGNBRK | |
110 | Ignore BREAK condition on input. | |
111 | .TP | |
112 | .B BRKINT | |
c13182ef MK |
113 | If \fBIGNBRK\fP is set, a BREAK is ignored. |
114 | If it is not set | |
fea681da MK |
115 | but \fBBRKINT\fP is set, then a BREAK causes the input and output |
116 | queues to be flushed, and if the terminal is the controlling | |
117 | terminal of a foreground process group, it will cause a | |
118 | \fBSIGINT\fP to be sent to this foreground process group. | |
119 | When neither \fBIGNBRK\fP nor \fBBRKINT\fP are set, a BREAK | |
28d88c17 | 120 | reads as a null byte ('\\0'), except when \fBPARMRK\fP is set, |
fea681da MK |
121 | in which case it reads as the sequence \\377 \\0 \\0. |
122 | .TP | |
123 | .B IGNPAR | |
124 | Ignore framing errors and parity errors. | |
125 | .TP | |
126 | .B PARMRK | |
c13182ef MK |
127 | If \fBIGNPAR\fP is not set, prefix a character with a parity error or |
128 | framing error with \\377 \\0. | |
129 | If neither \fBIGNPAR\fP nor \fBPARMRK\fP | |
fea681da MK |
130 | is set, read a character with a parity error or framing error |
131 | as \\0. | |
132 | .TP | |
133 | .B INPCK | |
134 | Enable input parity checking. | |
135 | .TP | |
136 | .B ISTRIP | |
137 | Strip off eighth bit. | |
138 | .TP | |
139 | .B INLCR | |
140 | Translate NL to CR on input. | |
141 | .TP | |
142 | .B IGNCR | |
143 | Ignore carriage return on input. | |
144 | .TP | |
145 | .B ICRNL | |
146 | Translate 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 | |
152 | Enable 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 | |
159 | Enable XON/XOFF flow control on input. | |
160 | .TP | |
161 | .B IMAXBEL | |
162 | (not in POSIX) Ring bell when input queue is full. | |
163 | Linux 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 | 167 | this 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 | |
172 | Enable implementation-defined output processing. | |
173 | .PP | |
68e1685c | 174 | The remaining \fIc_oflag\fP flag constants are defined in POSIX.1-2001, |
fea681da MK |
175 | unless 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 | |
184 | Map CR to NL on output. | |
185 | .TP | |
186 | .B ONOCR | |
187 | Don't output CR at column 0. | |
188 | .TP | |
189 | .B ONLRET | |
190 | Don't output CR. | |
191 | .TP | |
192 | .B OFILL | |
193 | Send 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 | 197 | If unset, fill character is ASCII NUL ('\\0'). |
42b09930 | 198 | (Not implemented on Linux.) |
fea681da MK |
199 | .TP |
200 | .B NLDLY | |
c13182ef MK |
201 | Newline delay mask. |
202 | Values are \fBNL0\fP and \fBNL1\fP. | |
869ebe5b | 203 | [requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE] |
fea681da MK |
204 | .TP |
205 | .B CRDLY | |
206 | Carriage return delay mask. | |
207 | Values 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 | |
211 | Horizontal tab delay mask. | |
212 | Values are \fBTAB0\fP, \fBTAB1\fP, \fBTAB2\fP, \fBTAB3\fP (or \fBXTABS\fP). | |
213 | A 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 |
218 | Backspace delay mask. |
219 | Values 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 |
224 | Vertical tab delay mask. |
225 | Values are \fBVT0\fP or \fBVT1\fP. | |
fea681da MK |
226 | .TP |
227 | .B FFDLY | |
c13182ef MK |
228 | Form feed delay mask. |
229 | Values 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 | 244 | structure without specifying where precisely, and provides |
63aa9df0 | 245 | .BR cfgetispeed () |
fea681da | 246 | and |
63aa9df0 | 247 | .BR cfsetispeed () |
c13182ef MK |
248 | for getting at it. |
249 | Some systems use bits selected by CBAUD in | |
fea681da | 250 | .IR c_cflag , |
75b94dc3 | 251 | other systems use separate fields, for example, |
fea681da MK |
252 | .I sg_ispeed |
253 | and | |
254 | .IR sg_ospeed .) | |
255 | .TP | |
256 | .B CSIZE | |
257 | Character size mask. | |
258 | Values are \fBCS5\fP, \fBCS6\fP, \fBCS7\fP, or \fBCS8\fP. | |
259 | .TP | |
260 | .B CSTOPB | |
261 | Set two stop bits, rather than one. | |
262 | .TP | |
263 | .B CREAD | |
264 | Enable receiver. | |
265 | .TP | |
266 | .B PARENB | |
267 | Enable parity generation on output and parity checking for input. | |
268 | .TP | |
269 | .B PARODD | |
c13182ef | 270 | If set, then parity for input and output is odd; |
19ab0376 | 271 | otherwise even parity is used. |
fea681da MK |
272 | .TP |
273 | .B HUPCL | |
274 | Lower modem control lines after last process closes the device (hang up). | |
275 | .TP | |
276 | .B CLOCAL | |
277 | Ignore modem control lines. | |
278 | .TP | |
279 | .B LOBLK | |
280 | (not in POSIX) Block output from a noncurrent shell layer. | |
42b09930 | 281 | For 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. |
285 | The values for the CIBAUD bits are | |
c13182ef | 286 | the 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 | 292 | Use "stick" (mark/space) parity (supported on certain serial |
4a837837 | 293 | devices): if |
c13182ef | 294 | .B PARODD |
adab6032 | 295 | is set, the parity bit is always 1; if |
c13182ef | 296 | .B PARODD |
adab6032 | 297 | is 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 | |
307 | When any of the characters INTR, QUIT, SUSP, or DSUSP are received, | |
308 | generate the corresponding signal. | |
309 | .TP | |
310 | .B ICANON | |
c13182ef | 311 | Enable canonical mode (described below). |
fea681da MK |
312 | .TP |
313 | .B XCASE | |
314 | (not in POSIX; not supported under Linux) | |
315 | If \fBICANON\fP is also set, terminal is uppercase only. | |
316 | Input is converted to lowercase, except for characters preceded by \\. | |
317 | On output, uppercase characters are preceded by \\ and lowercase | |
318 | characters 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 | |
323 | Echo input characters. | |
324 | .TP | |
325 | .B ECHOE | |
326 | If \fBICANON\fP is also set, the ERASE character erases the preceding | |
327 | input character, and WERASE erases the preceding word. | |
328 | .TP | |
329 | .B ECHOK | |
330 | If \fBICANON\fP is also set, the KILL character erases the current line. | |
331 | .TP | |
332 | .B ECHONL | |
333 | If \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 | |
337 | TAB, NL, START, and STOP are echoed as ^X, where X is the character with | |
c13182ef MK |
338 | ASCII code 0x40 greater than the control signal. |
339 | For example, character | |
fea681da | 340 | 0x08 (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 | |
345 | are 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 | |
350 | each 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 |
359 | Output is being flushed. |
360 | This flag is toggled by typing | |
fea681da | 361 | the DISCARD character. |
869ebe5b | 362 | [requires _BSD_SOURCE or _SVID_SOURCE] |
fea681da MK |
363 | .TP |
364 | .B NOFLSH | |
365 | Disable flushing the input and output queues when generating the SIGINT, | |
366 | SIGQUIT and SIGSUSP signals. | |
367 | .\" Stevens lets SIGSUSP only flush the input queue | |
368 | .TP | |
369 | .B TOSTOP | |
370 | Send the SIGTTOU signal to the process group of a background process | |
371 | which tries to write to its controlling terminal. | |
372 | .TP | |
373 | .B PENDIN | |
374 | (not in POSIX; not supported under Linux) | |
375 | All characters in the input queue are reprinted when | |
c13182ef MK |
376 | the 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 | |
381 | Enable implementation-defined input processing. | |
382 | This flag, as well as \fBICANON\fP must be enabled for the | |
383 | special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted, | |
384 | and for the \fBIUCLC\fP flag to be effective. | |
385 | .PP | |
386 | The \fIc_cc\fP array defines the special control characters. | |
387 | The symbolic indices (initial values) and meaning are: | |
388 | .TP | |
389 | .B VINTR | |
390 | (003, ETX, Ctrl-C, or also 0177, DEL, rubout) | |
c13182ef MK |
391 | Interrupt character. |
392 | Send a SIGINT signal. | |
fea681da MK |
393 | Recognized when ISIG is set, and then not passed as input. |
394 | .TP | |
395 | .B VQUIT | |
396 | (034, FS, Ctrl-\e) | |
c13182ef MK |
397 | Quit character. |
398 | Send SIGQUIT signal. | |
fea681da MK |
399 | Recognized 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 |
403 | Erase character. |
404 | This erases the previous not-yet-erased character, | |
fea681da MK |
405 | but does not erase past EOF or beginning-of-line. |
406 | Recognized 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 | 410 | Kill character. |
19ab0376 | 411 | This erases the input since the last EOF or beginning-of-line. |
fea681da MK |
412 | Recognized when ICANON is set, and then not passed as input. |
413 | .TP | |
414 | .B VEOF | |
415 | (004, EOT, Ctrl-D) | |
416 | End-of-file character. | |
417 | More precisely: this character causes the pending tty buffer to be sent | |
418 | to the waiting user program without waiting for end-of-line. | |
d9c1ae64 MK |
419 | If it is the first character of the line, the |
420 | .BR read (2) | |
421 | in the user program returns 0, which signifies end-of-file. | |
fea681da MK |
422 | Recognized when ICANON is set, and then not passed as input. |
423 | .TP | |
424 | .B VMIN | |
425 | Minimum number of characters for non-canonical read. | |
426 | .TP | |
427 | .B VEOL | |
428 | (0, NUL) | |
429 | Additional end-of-line character. | |
430 | Recognized when ICANON is set. | |
431 | .TP | |
432 | .B VTIME | |
433 | Timeout in deciseconds for non-canonical read. | |
434 | .TP | |
435 | .B VEOL2 | |
436 | (not in POSIX; 0, NUL) | |
437 | Yet another end-of-line character. | |
438 | Recognized when ICANON is set. | |
439 | .TP | |
440 | .B VSWTCH | |
441 | (not in POSIX; not supported under Linux; 0, NUL) | |
c13182ef MK |
442 | Switch character. |
443 | (Used by \fBshl\fP only.) | |
fea681da MK |
444 | .TP |
445 | .B VSTART | |
446 | (021, DC1, Ctrl-Q) | |
c13182ef MK |
447 | Start character. |
448 | Restarts output stopped by the Stop character. | |
fea681da MK |
449 | Recognized when IXON is set, and then not passed as input. |
450 | .TP | |
451 | .B VSTOP | |
452 | (023, DC3, Ctrl-S) | |
c13182ef MK |
453 | Stop character. |
454 | Stop output until Start character typed. | |
fea681da MK |
455 | Recognized when IXON is set, and then not passed as input. |
456 | .TP | |
457 | .B VSUSP | |
458 | (032, SUB, Ctrl-Z) | |
c13182ef MK |
459 | Suspend character. |
460 | Send SIGTSTP signal. | |
fea681da MK |
461 | Recognized 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) | |
465 | Delayed suspend character: | |
466 | send SIGTSTP signal when the character is read by the user program. | |
467 | Recognized when IEXTEN and ISIG are set, and the system supports | |
468 | job control, and then not passed as input. | |
469 | .TP | |
470 | .B VLNEXT | |
471 | (not in POSIX; 026, SYN, Ctrl-V) | |
c13182ef MK |
472 | Literal next. |
473 | Quotes the next input character, depriving it of | |
fea681da MK |
474 | a possible special meaning. |
475 | Recognized when IEXTEN is set, and then not passed as input. | |
476 | .TP | |
477 | .B VWERASE | |
478 | (not in POSIX; 027, ETB, Ctrl-W) | |
479 | Word erase. | |
480 | Recognized 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) | |
484 | Reprint unread characters. | |
485 | Recognized 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) | |
489 | Toggle: start/stop discarding pending output. | |
490 | Recognized when IEXTEN is set, and then not passed as input. | |
491 | .TP | |
492 | .B VSTATUS | |
493 | (not in POSIX; not supported under Linux; | |
494 | status request: 024, DC4, Ctrl-T). | |
495 | .LP | |
496 | These symbolic subscript values are all different, except that | |
497 | VTIME, VMIN may have the same value as VEOL, VEOF, respectively. | |
42b09930 | 498 | In non-canonical mode the special character meaning is replaced |
c13182ef MK |
499 | by the timeout meaning. |
500 | For an explanation of VMIN and VTIME, see the description of | |
19ab0376 | 501 | non-canonical mode below. |
87d1fd87 | 502 | .SS "Retrieving and changing terminal settings" |
fea681da | 503 | .PP |
63aa9df0 | 504 | .BR tcgetattr () |
fea681da | 505 | gets the parameters associated with the object referred by \fIfd\fP and |
869ebe5b | 506 | stores them in the \fItermios\fP structure referenced by |
c13182ef MK |
507 | \fItermios_p\fP. |
508 | This function may be invoked from a background process; | |
fea681da MK |
509 | however, the terminal attributes may be subsequently changed by a |
510 | foreground process. | |
511 | .LP | |
63aa9df0 | 512 | .BR tcsetattr () |
fea681da MK |
513 | sets the parameters associated with the terminal (unless support is |
514 | required 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 | |
518 | the change occurs immediately. | |
519 | .IP \fBTCSADRAIN\fP | |
520 | the change occurs after all output written to | |
521 | .I fd | |
c13182ef MK |
522 | has been transmitted. |
523 | This function should be used when changing | |
fea681da MK |
524 | parameters that affect output. |
525 | .IP \fBTCSAFLUSH\fP | |
526 | the change occurs after all output written to the object referred by | |
527 | .I fd | |
528 | has been transmitted, and all input that has been received but not read | |
529 | will be discarded before the change is made. | |
19ab0376 MK |
530 | .SS "Canonical and non-canonical mode" |
531 | The setting of the | |
532 | .B ICANON | |
533 | canon flag in | |
534 | .I c_lflag | |
535 | determines whether the terminal is operating in canonical mode | |
536 | .RB ( ICANON | |
537 | set) or | |
538 | non-canonical mode | |
c13182ef | 539 | .RB ( ICANON |
19ab0376 MK |
540 | unset). |
541 | By default, | |
542 | .B ICANON | |
543 | set. | |
544 | ||
545 | In canonical mode: | |
546 | .IP * 2 | |
547 | Input is made available line by line. | |
548 | An input line is available when one of the line delimiters | |
549 | is typed (NL, EOL, EOL2; or EOF at the start of line). | |
550 | Except in the case of EOF, the line delimiter is included | |
551 | in the buffer returned by | |
552 | .BR read (2). | |
553 | .IP * 2 | |
c13182ef MK |
554 | Line editing is enabled (ERASE, KILL; |
555 | and if the | |
19ab0376 MK |
556 | .B IEXTEN |
557 | flag is set: WERASE, REPRINT, LNEXT). | |
c13182ef | 558 | A |
fb186734 | 559 | .BR read (2) |
19ab0376 | 560 | returns at most one line of input; if the |
fb186734 | 561 | .BR read (2) |
19ab0376 MK |
562 | requested fewer bytes than are available in the current line of input, |
563 | then only as many bytes as requested are read, | |
564 | and the remaining characters will be available for a future | |
fb186734 | 565 | .BR read (2). |
19ab0376 | 566 | .PP |
c13182ef | 567 | In non-canonical mode input is available immediately (without |
19ab0376 MK |
568 | the user having to type a line-delimiter character), |
569 | and line editing is disabled. | |
c13182ef | 570 | The settings of MIN |
19ab0376 | 571 | .RI ( c_cc[VMIN] ) |
0f8b10eb | 572 | and TIME |
19ab0376 MK |
573 | .RI ( c_cc[VTIME] ) |
574 | determine the circumstances in which a | |
575 | .BR read (2) | |
576 | completes; there are four distinct cases: | |
577 | .IP * 2 | |
578 | MIN == 0; TIME == 0: | |
579 | If data is available, | |
fb186734 | 580 | .BR read (2) |
19ab0376 MK |
581 | returns immediately, with the lesser of the number of bytes |
582 | available, or the number of bytes requested. | |
583 | If no data is available, | |
fb186734 | 584 | .BR read (2) |
19ab0376 MK |
585 | returns 0. |
586 | .IP * 2 | |
587 | MIN > 0; TIME == 0: | |
fb186734 | 588 | .BR read (2) |
19ab0376 MK |
589 | blocks until the lesser of MIN bytes or the number of bytes requested |
590 | are available, and returns the lesser of these two values. | |
591 | .IP * 2 | |
592 | MIN == 0; TIME > 0: | |
593 | TIME specifies the limit for a timer in tenths of a second. | |
c13182ef | 594 | The timer is started when |
fb186734 | 595 | .BR read (2) |
19ab0376 | 596 | is called. |
fb186734 | 597 | .BR read (2) |
19ab0376 MK |
598 | returns either when at least one byte of data is available, |
599 | or when the timer expires. | |
600 | If the timer expires without any input becoming available, | |
fb186734 | 601 | .BR read (2) |
19ab0376 MK |
602 | returns 0. |
603 | .IP * 2 | |
604 | MIN > 0; TIME > 0: | |
605 | TIME specifies the limit for a timer in tenths of a second. | |
606 | Once an initial byte of input becomes available, | |
607 | the timer is restarted after each further byte is received. | |
fb186734 | 608 | .BR read (2) |
c13182ef | 609 | returns either when the lesser of the number of bytes requested or |
19ab0376 MK |
610 | MIN byte have been read, |
611 | or when the inter-byte timeout expires. | |
c13182ef | 612 | Because the timer is only started after the initial byte |
19ab0376 MK |
613 | becomes available, at least one byte will be read. |
614 | .SS "Raw mode" | |
615 | .LP | |
60a90ecd MK |
616 | .BR cfmakeraw () |
617 | sets the terminal to something like the | |
1954b6a9 | 618 | "raw" mode of the old Version 7 terminal driver: |
19ab0376 | 619 | input is available character by character, |
c13182ef | 620 | echoing is disabled, and all special processing of |
19ab0376 MK |
621 | terminal input and output characters is disabled. |
622 | The 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 |
635 | transmits a continuous stream of zero-valued bits for a specific |
636 | duration, if the terminal is using asynchronous serial data | |
c13182ef MK |
637 | transmission. |
638 | If \fIduration\fP is zero, it transmits zero-valued bits | |
639 | for at least 0.25 seconds, and not more that 0.5 seconds. | |
640 | If \fIduration\fP is not zero, it sends zero-valued bits for some | |
fea681da MK |
641 | implementation-defined length of time. |
642 | .LP | |
643 | If the terminal is not using asynchronous serial data transmission, | |
60a90ecd MK |
644 | .BR tcsendbreak () |
645 | returns without taking any action. | |
fea681da | 646 | .LP |
63aa9df0 | 647 | .BR tcdrain () |
fea681da MK |
648 | waits until all output written to the object referred to by |
649 | .I fd | |
650 | has been transmitted. | |
651 | .LP | |
63aa9df0 | 652 | .BR tcflush () |
fea681da MK |
653 | discards data written to the object referred to by |
654 | .I fd | |
655 | but not transmitted, or data received but not read, depending on the | |
656 | value of | |
657 | .IR queue_selector : | |
658 | .IP \fBTCIFLUSH\fP | |
659 | flushes data received but not read. | |
660 | .IP \fBTCOFLUSH\fP | |
661 | flushes data written but not transmitted. | |
662 | .IP \fBTCIOFLUSH\fP | |
663 | flushes both data received but not read, and data written but not | |
664 | transmitted. | |
665 | .LP | |
63aa9df0 | 666 | .BR tcflow () |
fea681da MK |
667 | suspends transmission or reception of data on the object referred to by |
668 | .IR fd , | |
669 | depending on the value of | |
670 | .IR action : | |
671 | .IP \fBTCOOFF\fP | |
672 | suspends output. | |
673 | .IP \fBTCOON\fP | |
674 | restarts suspended output. | |
675 | .IP \fBTCIOFF\fP | |
c13182ef | 676 | transmits a STOP character, which stops the terminal device from |
35478399 | 677 | transmitting data to the system. |
fea681da | 678 | .IP \fBTCION\fP |
c13182ef | 679 | transmits a START character, which starts the terminal device |
35478399 | 680 | transmitting data to the system. |
fea681da MK |
681 | .LP |
682 | The default on open of a terminal file is that neither its input nor its | |
683 | output is suspended. | |
87d1fd87 MK |
684 | .SS "Line speed" |
685 | The baud rate functions are provided for getting and setting the values | |
c13182ef MK |
686 | of the input and output baud rates in the \fItermios\fP structure. |
687 | The new values do not take effect | |
60a90ecd MK |
688 | until |
689 | .BR tcsetattr () | |
690 | is successfully called. | |
87d1fd87 MK |
691 | |
692 | Setting the speed to \fBB0\fP instructs the modem to "hang up". | |
693 | The actual bit rate corresponding to \fBB38400\fP may be altered with | |
60a90ecd | 694 | .BR setserial (8). |
87d1fd87 MK |
695 | .LP |
696 | The input and output baud rates are stored in the \fItermios\fP | |
697 | structure. | |
fea681da | 698 | .LP |
63aa9df0 | 699 | .BR cfgetospeed () |
869ebe5b | 700 | returns the output baud rate stored in the \fItermios\fP structure |
fea681da MK |
701 | pointed to by |
702 | .IR termios_p . | |
703 | .LP | |
63aa9df0 | 704 | .BR cfsetospeed () |
869ebe5b | 705 | sets the output baud rate stored in the \fItermios\fP structure pointed |
fea681da MK |
706 | to 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 |
732 | The zero baud rate, \fBB0\fP, | |
c13182ef MK |
733 | is used to terminate the connection. |
734 | If B0 is specified, the modem control lines shall no longer be asserted. | |
be7fff26 MK |
735 | Normally, this will disconnect the line. |
736 | \fBCBAUDEX\fP is a mask | |
fea681da | 737 | for the speeds beyond those defined in POSIX.1 (57600 and above). |
f59a3f19 | 738 | Thus, \fBB57600\fP & \fBCBAUDEX\fP is non-zero. |
fea681da | 739 | .LP |
63aa9df0 | 740 | .BR cfgetispeed () |
869ebe5b | 741 | returns the input baud rate stored in the \fItermios\fP structure. |
fea681da | 742 | .LP |
63aa9df0 | 743 | .BR cfsetispeed () |
869ebe5b | 744 | sets the input baud rate stored in the \fItermios\fP structure to |
c13182ef | 745 | .IR speed , |
869ebe5b MK |
746 | which must be specified as one of the \fBBnnn\fP constants listed above for |
747 | .BR cfsetospeed (). | |
fea681da MK |
748 | If the input baud rate is set to zero, the input baud rate will be |
749 | equal to the output baud rate. | |
750 | .LP | |
63aa9df0 | 751 | .BR cfsetspeed () |
c13182ef MK |
752 | is a 4.4BSD extension. |
753 | It takes the same arguments as | |
869ebe5b MK |
754 | .BR cfsetispeed (), |
755 | and sets both input and output speed. | |
fea681da MK |
756 | .SH "RETURN VALUE" |
757 | .LP | |
63aa9df0 | 758 | .BR cfgetispeed () |
fea681da | 759 | returns the input baud rate stored in the |
869ebe5b | 760 | \fItermios\fP |
fea681da MK |
761 | structure. |
762 | .LP | |
63aa9df0 | 763 | .BR cfgetospeed () |
869ebe5b | 764 | returns the output baud rate stored in the \fItermios\fP structure. |
fea681da MK |
765 | .LP |
766 | All other functions return: | |
767 | .IP 0 | |
768 | on success. | |
769 | .IP \-1 | |
770 | on failure and set | |
771 | .I errno | |
772 | to indicate the error. | |
773 | .LP | |
774 | Note that | |
f87925c6 | 775 | .BR tcsetattr () |
fea681da | 776 | returns success if \fIany\fP of the requested changes could be |
c13182ef MK |
777 | successfully carried out. |
778 | Therefore, when making multiple changes | |
fea681da | 779 | it may be necessary to follow this call with a further call to |
f87925c6 | 780 | .BR tcgetattr () |
fea681da | 781 | to 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 (), | |
792 | and | |
793 | .BR cfsetospeed () | |
794 | are specified in POSIX.1-2001. | |
795 | ||
796 | .BR cfmakeraw () | |
797 | is non-standard, but available on the BSDs. | |
fea681da MK |
798 | .SH NOTES |
799 | Unix V7 and several later systems have a list of baud rates | |
800 | where after the fourteen values B0, ..., B9600 one finds the | |
801 | two constants EXTA, EXTB ("External A" and "External B"). | |
802 | Many systems extend the list with much higher baud rates. | |
803 | .LP | |
60a90ecd MK |
804 | The effect of a non-zero \fIduration\fP with |
805 | .BR tcsendbreak () | |
806 | varies. | |
c13182ef | 807 | SunOS specifies a break of |
fea681da MK |
808 | .IB duration * N |
809 | seconds, where \fIN\fP is at least 0.25, and not more than 0.5. | |
810 | Linux, AIX, DU, Tru64 send a break of | |
811 | .I duration | |
812 | milliseconds. | |
813 | FreeBSD and NetBSD and HP-UX and MacOS ignore the value of | |
814 | .IR duration . | |
815 | Under Solaris and Unixware, | |
e511ffb6 | 816 | .BR tcsendbreak () |
f59a3f19 | 817 | with non-zero |
fea681da MK |
818 | .I duration |
819 | behaves 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) |