1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
|
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (c) 1993 Michael Haardt
.\" (u31b3hs@pool.informatik.rwth-aachen.de)
.\" Fri Apr 2 11:32:09 MET DST 1993
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
.\" USA.
.\"
.\" Modified Sat Jul 24 15:37:39 1993 by Rik Faith (faith@cs.unc.edu)
.\" Modified Sat Feb 25 18:17:14 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
.\" Modified Sat Sep 2 22:33:09 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
.\" moved to man3, aeb, 950919
.\"
.TH TERMIOS 3 "September 2, 1995" "Linux" "Linux Programmer's Manual"
.SH NAME
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed,
tcgetpgrp, tcsetpgrp \- get and set
terminal attributes, line control, get and set baud rate, get and set
terminal foreground process group ID
.SH SYNOPSIS
.ad l
.ft B
#include <termios.h>
.br
#include <unistd.h>
.sp
.BI "int tcgetattr ( int " fd ", struct termios *" termios_p " );"
.sp
.BI "int tcsetattr ( int " fd ", int " optional_actions ", struct termios *" termios_p " );"
.sp
.BI "int tcsendbreak ( int " fd ", int " duration " );"
.sp
.BI "int tcdrain ( int " fd " );"
.sp
.BI "int tcflush ( int " fd ", int " queue_selector " );"
.sp
.BI "int tcflow ( int " fd ", int " action " );"
.sp
.BI "int cfmakeraw ( struct termios *" termios_p " );"
.sp
.BI "speed_t cfgetospeed ( struct termios *" termios_p " );"
.sp
.BI "int cfsetospeed ( struct termios *" termios_p ", speed_t " speed " );"
.sp
.BI "speed_t cfgetispeed ( struct termios *" termios_p " );"
.sp
.BI "int cfsetispeed ( struct termios *" termios_p ", speed_t " speed " );"
.sp
.BI "pid_t tcgetpgrp ( int " fd " );"
.sp
.BI "int tcsetpgrp ( int " fd ", pid_t " pgrpid " );"
.ft P
.ad b
.SH DESCRIPTION
The termios functions describe a general terminal interface that is
provided to control asynchronous communications ports.
.LP
Many of the functions described here have a \fItermios_p\fP argument
that is a pointer to a \fBtermios\fP structure. This structure contains
the following members:
.ne 9
.sp
.RS
.nf
tcflag_t \fIc_iflag\fP; /* input modes */
tcflag_t \fIc_oflag\fP; /* output modes */
tcflag_t \fIc_cflag\fP; /* control modes */
tcflag_t \fIc_lflag\fP; /* local modes */
cc_t \fIc_cc\fP[\fBNCCS\fP]; /* control chars */
.RE
.sp
.fi
.PP
\fIc_iflag\fP flag constants:
.IP \fBIGNBRK\fP
ignore BREAK condition on input
.IP \fBBRKINT\fP
If \fBIGNBRK\fP is not set, generate \fBSIGINT\fP on BREAK condition,
else read BREAK as character \\0.
.IP \fBIGNPAR\fP
ignore framing errors and parity errors.
.IP \fBPARMRK\fP
if \fBIGNPAR\fP is not set, prefix a character with a parity error or
framing error with \\377 \\0. If neither \fBIGNPAR\fP nor \fBPARMRK\fP
is set, read a character with a parity error or framing error
as \\0.
.IP \fBINPCK\fP
enable input parity checking
.IP \fBISTRIP\fP
strip off eighth bit
.IP \fBINLCR\fP
translate NL to CR on input
.IP \fBIGNCR\fP
ignore carriage return on input
.IP \fBICRNL\fP
translate carriage return to newline on input (unless \fBIGNCR\fP is set)
.IP \fBIUCLC\fP
map uppercase characters to lowercase on input
.IP \fBIXON\fP
enable XON/XOFF flow control on output
.IP \fBIXANY\fP
enable any character to restart output
.IP \fBIXOFF\fP
enable XON/XOFF flow control on input
.IP \fBIMAXBEL\fP
ring bell when input queue is full
.PP
\fIc_oflag\fP flag constants:
.IP \fBOPOST\fP
enable implementation-defined output processing
.IP \fBOLCUC\fP
map lowercase characters to uppercase on output
.IP \fBONLCR\fP
map NL to CR-NL on output
.IP \fBOCRNL\fP
map CR to NL on output
.IP \fBONOCR\fP
don't output CR at column 0
.IP \fBONLRET\fP
don't output CR
.IP \fBOFILL\fP
send fill characters for a delay, rather than using a timed delay
.IP \fBOFDEL\fP
fill character is ASCII DEL. If unset, fill character is ASCII NUL
.IP \fBNLDLY\fP
newline delay mask. Values are \fBNL0\fP and \fBNL1\fP.
.IP \fBCRDLY\fP
carriage return delay mask. Values are \fBCR0\fP, \fBCR1\fP, \fBCR2\fP, or \fBCR3\fP.
.IP \fBTABDLY\fP
horizontal tab delay mask. Values are \fBTAB0\fP, \fBTAB1\fP, \fBTAB2\fP, \fBTAB3\fP, or \fBXTABS\fP.
A value of XTABS expands tabs to spaces (with tab stops every eight columns).
.IP \fBBSDLY\fP
backspace delay mask. Values are \fBBS0\fP or \fBBS1\fP.
.IP \fBVTDLY\fP
vertical tab delay mask. Values are \fBVT0\fP or \fBVT1\fP.
.IP \fBFFDLY\fP
form feed delay mask. Values are \fBFF0\fP or \fBFF1\fP.
.PP
\fIc_cflag\fP flag constants:
.IP \fBCSIZE\fP
character size mask. Values are \fBCS5\fP, \fBCS6\fP, \fBCS7\fP, or \fBCS8\fP.
.IP \fBCSTOPB\fP
set two stop bits, rather than one.
.IP \fBCREAD\fP
enable receiver.
.IP \fBPARENB\fP
enable parity generation on output and parity checking for input.
.IP \fBPARODD\fP
parity for input and output is odd.
.IP \fBHUPCL\fP
lower modem control lines after last process closes the device (hang up).
.IP \fBCLOCAL\fP
ignore modem control lines
.IP \fBCIBAUD\fP
mask for input speeds (not used).
.IP \fBCRTSCTS\fP
flow control.
.PP
\fIc_lflag\fP flag constants:
.IP \fBISIG\fP
when any of the characters INTR, QUIT, SUSP, or DSUSP are received,
generate the corresponding signal.
.IP \fBICANON\fP
enable canonical mode. This enables the special characters
EOF, EOL, EOL2, ERASE, KILL, REPRINT, STATUS, and WERASE, and
buffers by lines.
.IP \fBXCASE\fP
if \fBICANON\fP is also set, terminal is uppercase only.
Input is converted to lowercase, except for characters preceded by \\.
On output, uppercase characters are preceded by \\ and lowercase
characters are converted to uppercase.
.IP \fBECHO\fP
echo input characters.
.IP \fBECHOE\fP
if \fBICANON\fP is also set, the ERASE character erases the preceding
input character, and WERASE erases the preceding word.
.IP \fBECHOK\fP
if \fBICANON\fP is also set, the KILL character erases the current line.
.IP \fBECHONL\fP
if \fBICANON\fP is also set, echo the NL character even if ECHO is not set.
.IP \fBECHOCTL\fP
if \fBECHO\fP is also set, ASCII control signals other than TAB, NL, START, and STOP
are echoed as ^X, where X is the character with ASCII code 0x40 greater
than the control signal. For example, character 0x08 (BS) is echoed as ^H.
.IP \fBECHOPRT\fP
if \fBICANON\fP and \fBIECHO\fP are also set, characters are printed as they
are being erased.
.IP \fBECHOKE\fP
if \fBICANON\fP is also set, KILL is echoed by erasing each character on the line,
as specified by \fBECHOE\fP and \fBECHOPRT\fP.
.IP \fBFLUSHO\fP
output is being flushed. This flag is toggled by typing the DISCARD character.
.IP \fBNOFLSH\fP
disable flushing the input and output queues when generating the SIGINT
and SIGQUIT signals, and flushing the input queue when generating
the SIGSUSP signal.
.IP \fBTOSTOP\fP
send the SIGTTOU signal to the process group of a background process
which tries to write to its controlling terminal.
.IP \fBPENDIN\fP
all characters in the input queue are reprinted when the next character is
read. (\fBbash\fP handles typeahead this way.)
.IP \fBIEXTEN\fP
enable implementation-defined input processing.
.PP
.B tcgetattr()
gets the parameters associated with the object referred by \fIfd\fP and
stores them in the \fBtermios\fP structure referenced by
\fItermios_p\fP. This function may be invoked from a background process;
however, the terminal attributes may be subsequently changed by a
foreground process.
.LP
.B tcsetattr()
sets the parameters associated with the terminal (unless support is
required from the underlying hardware that is not available) from the
\fBtermios\fP structure referred to by \fItermios_p\fP.
\fIoptional_actions\fP specifies when the changes take effect:
.IP \fBTCSANOW\fP
the change occurs immediately.
.IP \fBTCSADRAIN\fP
the change occurs after all output written to
.I fd
has been transmitted. This function should be used when changing
parameters that affect output.
.IP \fBTCSAFLUSH\fP
the change occurs after all output written to the object referred by
.I fd
has been transmitted, and all input that has been received but not read
will be discarded before the change is made.
.LP
.B tcsendbreak()
transmits a continuous stream of zero-valued bits for a specific
duration, if the terminal is using asynchronous serial data
transmission. If \fIduration\fP is zero, it transmits zero-valued bits
for at least 0.25 seconds, and not more that 0.5 seconds. If
\fIduration\fP is not zero, it sends zero-valued bits for
.IB duration * N
seconds, where \fIN\fP is at least 0.25, and not more than 0.5.
.LP
If the terminal is not using asynchronous serial data transmission,
\fBtcsendbreak()\fP returns without taking any action.
.LP
.B tcdrain()
waits until all output written to the object referred to by
.I fd
has been transmitted.
.LP
.B tcflush()
discards data written to the object referred to by
.I fd
but not transmitted, or data received but not read, depending on the
value of
.IR queue_selector :
.IP \fBTCIFLUSH\fP
flushes data received but not read.
.IP \fBTCOFLUSH\fP
flushes data written but not transmitted.
.IP \fBTCIOFLUSH\fP
flushes both data received but not read, and data written but not
transmitted.
.LP
.B tcflow()
suspends transmission or reception of data on the object referred to by
.IR fd ,
depending on the value of
.IR action :
.IP \fBTCOOFF\fP
suspends output.
.IP \fBTCOON\fP
restarts suspended output.
.IP \fBTCIOFF\fP
transmits a STOP character, which stops the terminal device from transmitting data to the
system.
.IP \fBTCION\fP
transmits a START character, which starts the terminal device transmitting data to the
system.
.LP
The default on open of a terminal file is that neither its input nor its
output is suspended.
.LP
The baud rate functions are provided for getting and setting the values
of the input and output baud rates in the \fBtermios\fP structure. The
new values do not take effect
until \fBtcsetattr()\fP is successfully called.
Setting the speed to \fBB0\fP instructs the modem to "hang up".
The actual bit rate corresponding to \fBB38400\fP may be altered with
\fBsetserial\fP(8).
.LP
The input and output baud rates are stored in the \fBtermios\fP
structure.
.LP
\fBcfmakeraw\fP sets the terminal attributes as follows:
.nf
termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
|INLCR|IGNCR|ICRNL|IXON);
termios_p->c_oflag &= ~OPOST;
termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
termios_p->c_cflag &= ~(CSIZE|PARENB);
termios_p->c_cflag |= CS8;
.fi
.LP
.B cfgetospeed()
returns the output baud rate stored in the \fBtermios\fP structure
pointed to by
.IR termios_p .
.LP
.B cfsetospeed()
sets the output baud rate stored in the \fBtermios\fP structure pointed
to by \fItermios_p\fP to \fIspeed\fP, which must be one of these constants:
.nf
.ft B
B0
B50
B75
B110
B134
B150
B200
B300
B600
B1200
B1800
B2400
B4800
B9600
B19200
B38400
B57600
B115200
B230400
.ft P
.fi
The zero baud rate, \fBB0\fP,
is used to terminate the connection. If B0
is specified, the modem control lines shall no longer be asserted.
Normally, this will disconnect the line. \fBCBAUDEX\fP is a mask
for the speeds beyond those defined in POSIX.1 (57600 and above).
Thus, \fBB57600\fP & \fBCBAUDEX\fP is nonzero.
.LP
.B cfgetispeed()
returns the input baud rate stored in the \fBtermios\fP structure.
.LP
.B cfsetispeed()
sets the input baud rate stored in the \fBtermios\fP structure to
.IR speed .
If the input baud rate is set to zero, the input baud rate will be
equal to the output baud rate.
.LP
.B tcgetpgrp()
returns process group ID of foreground processing group, or -1 on error.
.LP
.B tcsetpgrp()
sets process group ID to \fIpgrpid\fP. \fIpgrpid\fP must be the ID
of a process group in the same session.
.SH "RETURN VALUES"
.LP
.B cfgetispeed()
returns the input baud rate stored in the
\fBtermios\fP
structure.
.LP
.B cfgetospeed()
returns the output baud rate stored in the \fBtermios\fP structure.
.LP
.B tcgetpgrp()
returns process group ID of foreground processing group, or -1 on error.
.LP
All other functions return:
.IP 0
on success.
.IP -1
on failure and set
.I errno
to indicate the error.
.SH "SEE ALSO"
\fBsetserial\fP(8)
|