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