1.\" $OpenBSD: termios.4,v 1.14 2001/06/22 12:15:47 mpech Exp $ 2.\" $NetBSD: termios.4,v 1.5 1994/11/30 16:22:36 jtc Exp $ 3.\" 4.\" Copyright (c) 1991, 1992, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)termios.4 8.4 (Berkeley) 4/19/94 36.\" 37.Dd April 19, 1994 38.Dt TERMIOS 4 39.Os 40.Sh NAME 41.Nm termios 42.Nd general terminal line discipline 43.Sh SYNOPSIS 44.Fd #include <termios.h> 45.Sh DESCRIPTION 46This describes a general terminal line discipline that is 47supported on tty asynchronous communication ports. 48.Ss Opening a Terminal Device File 49When a terminal file is opened, it normally causes the process to wait 50until a connection is established. For most hardware, the presence 51of a connection is indicated by the assertion of the hardware 52.Dv CARRIER line. 53If the termios structure associated with the terminal file has the 54.Dv CLOCAL 55flag set in the cflag, or if the 56.Dv O_NONBLOCK 57flag is set 58in the 59.Xr open 2 60call, then the open will succeed even without 61a connection being present. 62In practice, applications 63seldom open these files; they are opened by special programs, such 64as 65.Xr getty 8 66or 67.Xr rlogind 8 , 68and become 69an application's standard input, output, and error files. 70.Ss Job Control in a Nutshell 71Every process is associated with a particular process group and session. 72The grouping is hierarchical: every member of a particular process group is a 73member of the same session. This structuring is used in managing groups 74of related processes for purposes of 75.\" .Gw "job control" ; 76.Em "job control" ; 77that is, the 78ability from the keyboard (or from program control) to simultaneously 79stop or restart 80a complex command (a command composed of one or more related 81processes). The grouping into process groups allows delivering 82of signals that stop or start the group as a whole, along with 83arbitrating which process group has access to the single controlling 84terminal. The grouping at a higher layer into sessions is to restrict 85the job control related signals and system calls to within processes 86resulting from a particular instance of a "login". Typically, a session 87is created when a user logs in, and the login terminal is setup 88to be the controlling terminal; all processes spawned from that 89login shell are in the same session, and inherit the controlling 90terminal. 91A job control shell 92operating interactively (that is, reading commands from a terminal) 93normally groups related processes together by placing them into the 94same process group. A set of processes in the same process group 95is collectively referred to as a "job". When the foreground process 96group of the terminal is the same as the process group of a particular 97job, that job is said to be in the "foreground". When the process 98group of the terminal is different than the process group of 99a job (but is still the controlling terminal), that job is said 100to be in the "background". Normally the 101shell reads a command and starts the job that implements that 102command. If the command is to be started in the foreground (typical), it 103sets the process group of the terminal to the process group 104of the started job, waits for the job to complete, and then 105sets the process group of the terminal back to its own process 106group (it puts itself into the foreground). If the job is to 107be started in the background (as denoted by the shell operator "&"), 108it never changes the process group of the terminal and doesn't 109wait for the job to complete (that is, it immediately attempts to read the next 110command). If the job is started in the foreground, the user may 111type a key (usually 112.Ql \&^Z ) 113which generates the terminal stop signal 114.Pq Dv SIGTSTP 115and has the effect of stopping the entire job. 116The shell will notice that the job stopped, and will resume running after 117placing itself in the foreground. 118The shell also has commands for placing stopped jobs in the background, 119and for placing stopped or background jobs into the foreground. 120.Ss Orphaned Process Groups 121An orphaned process group is a process group that has no process 122whose parent is in a different process group, yet is in the same 123session. Conceptually it means a process group that doesn't have 124a parent that could do anything if it were to be stopped. For example, 125the initial login shell is typically in an orphaned process group. 126Orphaned process groups are immune to keyboard generated stop 127signals and job control signals resulting from reads or writes to the 128controlling terminal. 129.Ss The Controlling Terminal 130A terminal may belong to a process as its controlling terminal. Each 131process of a session that has a controlling terminal has the same 132controlling terminal. A terminal may be the controlling terminal for at 133most one session. The controlling terminal for a session is allocated by 134the session leader by issuing the 135.Dv TIOCSCTTY 136ioctl. A controlling terminal 137is never acquired by merely opening a terminal device file. 138When a controlling terminal becomes 139associated with a session, its foreground process group is set to 140the process group of the session leader. 141.Pp 142The controlling terminal is inherited by a child process during a 143.Xr fork 2 144function call. A process relinquishes its controlling terminal when it 145creates a new session with the 146.Xr setsid 2 147function; other processes 148remaining in the old session that had this terminal as their controlling 149terminal continue to have it. 150A process does not relinquish its 151controlling terminal simply by closing all of its file descriptors 152associated with the controlling terminal if other processes continue to 153have it open. 154.Pp 155When a controlling process terminates, the controlling terminal is 156disassociated from the current session, allowing it to be acquired by a 157new session leader. Subsequent access to the terminal by other processes 158in the earlier session will be denied, with attempts to access the 159terminal treated as if modem disconnect had been sensed. 160.Ss Terminal Access Control 161If a process is in the foreground process group of its controlling 162terminal, read operations are allowed. 163Any attempts by a process 164in a background process group to read from its controlling terminal 165causes a 166.Dv SIGTTIN 167signal to be sent to 168the process's group 169unless one of the 170following special cases apply: If the reading process is ignoring or 171blocking the 172.Dv SIGTTIN signal, or if the process group of the reading 173process is orphaned, the 174.Xr read 2 175returns -1 with 176.Va errno 177set to 178.Er Dv EIO 179and no 180signal is sent. The default action of the 181.Dv SIGTTIN 182signal is to stop the 183process to which it is sent. 184.Pp 185If a process is in the foreground process group of its controlling 186terminal, write operations are allowed. 187Attempts by a process in a background process group to write to its 188controlling terminal will cause the process group to be sent a 189.Dv SIGTTOU 190signal unless one of the following special cases apply: If 191.Dv TOSTOP 192is not 193set, or if 194.Dv TOSTOP 195is set and the process is ignoring or blocking the 196.Dv SIGTTOU 197signal, the process is allowed to write to the terminal and the 198.Dv SIGTTOU 199signal is not sent. If 200.Dv TOSTOP 201is set, and the process group of 202the writing process is orphaned, and the writing process is not ignoring 203or blocking 204.Dv SIGTTOU , 205the 206.Xr write 207returns -1 with 208.Va errno 209set to 210.Er Dv EIO 211and no signal is sent. 212.Pp 213Certain calls that set terminal parameters are treated in the same 214fashion as write, except that 215.Dv TOSTOP 216is ignored; that is, the effect is 217identical to that of terminal writes when 218.Dv TOSTOP 219is set. 220.Ss Input Processing and Reading Data 221A terminal device associated with a terminal device file may operate in 222full-duplex mode, so that data may arrive even while output is occurring. 223Each terminal device file has associated with it an input queue, into 224which incoming data is stored by the system before being read by a 225process. The system imposes a limit, 226.Pf \&{ Dv MAX_INPUT Ns \&} , 227on the number of 228bytes that may be stored in the input queue. The behavior of the system 229when this limit is exceeded depends on the setting of the 230.Dv IMAXBEL 231flag in the termios 232.Fa c_iflag . 233If this flag is set, the terminal 234is sent an 235.Tn ASCII 236.Dv BEL 237character each time a character is received 238while the input queue is full. Otherwise, the input queue is flushed 239upon receiving the character. 240.Pp 241Two general kinds of input processing are available, determined by 242whether the terminal device file is in canonical mode or noncanonical 243mode. Additionally, 244input characters are processed according to the 245.Fa c_iflag 246and 247.Fa c_lflag 248fields. Such processing can include echoing, which 249in general means transmitting input characters immediately back to the 250terminal when they are received from the terminal. This is useful for 251terminals that can operate in full-duplex mode. 252.Pp 253The manner in which data is provided to a process reading from a terminal 254device file is dependent on whether the terminal device file is in 255canonical or noncanonical mode. 256.Pp 257Another dependency is whether the 258.Dv O_NONBLOCK 259flag is set by 260.Xr open() 261or 262.Xr fcntl() . 263If the 264.Dv O_NONBLOCK 265flag is clear, then the read request is 266blocked until data is available or a signal has been received. If the 267.Dv O_NONBLOCK 268flag is set, then the read request is completed, without 269blocking, in one of three ways: 270.Bl -enum -offset indent 271.It 272If there is enough data available to satisfy the entire request, 273and the read completes successfully the number of 274bytes read is returned. 275.It 276If there is not enough data available to satisfy the entire 277request, and the read completes successfully, having read as 278much data as possible, the number of bytes read is returned. 279.It 280If there is no data available, the read returns -1, with 281.Va errno 282set to 283.Er EAGAIN . 284.El 285.Pp 286When data is available depends on whether the input processing mode is 287canonical or noncanonical. 288.Ss Canonical Mode Input Processing 289In canonical mode input processing, terminal input is processed in units 290of lines. A line is delimited by a newline 291.Ql \&\en 292character, an end-of-file 293.Pq Dv EOF 294character, or an end-of-line 295.Pq Dv EOL 296character. See the 297.Sx "Special Characters" 298section for 299more information on 300.Dv EOF 301and 302.Dv EOL . 303This means that a read request will 304not return until an entire line has been typed, or a signal has been 305received. Also, no matter how many bytes are requested in the read call, 306at most one line is returned. It is not, however, necessary to 307read a whole line at once; any number of bytes, even one, may be 308requested in a read without losing information. 309.Pp 310.Pf \&{ Dv MAX_CANON Ns \&} 311is a limit on the 312number of bytes in a line. 313The behavior of the system when this limit is 314exceeded is the same as when the input queue limit 315.Pf \&{ Dv MAX_INPUT Ns \&} , 316is exceeded. 317.Pp 318Erase and kill processing occur when either of two special characters, 319the 320.Dv ERASE 321and 322.Dv KILL 323characters (see the 324.Sx "Special Characters section" ) , 325is received. 326This processing affects data in the input queue that has not yet been 327delimited by a newline 328.Dv NL, 329.Dv EOF , 330or 331.Dv EOL 332character. This un-delimited 333data makes up the current line. The 334.Dv ERASE 335character deletes the last 336character in the current line, if there is any. The 337.Dv KILL 338character 339deletes all data in the current line, if there is any. The 340.Dv ERASE 341and 342.Dv KILL 343characters have no effect if there is no data in the current line. 344The 345.Dv ERASE 346and 347.Dv KILL 348characters themselves are not placed in the input 349queue. 350.Ss Noncanonical Mode Input Processing 351In noncanonical mode input processing, input bytes are not assembled into 352lines, and erase and kill processing does not occur. The values of the 353.Dv VMIN 354and 355.Dv VTIME 356members of the 357.Fa c_cc 358array are used to determine how to 359process the bytes received. 360.Pp 361.Dv VMIN 362represents the minimum number of bytes that should be received when 363the 364.Xr read 365function successfully returns. 366.Dv VTIME 367is a timer of 0.1 second 368granularity that is used to time out bursty and short term data 369transmissions. If 370.Dv VMIN 371is greater than 372.Pf \&{ Dv MAX_INPUT Ns \&} , 373the response to the 374request is undefined. The four possible values for 375.Dv VMIN 376and 377.Dv VTIME 378and 379their interactions are described below. 380.Ss "Case A: VMIN > 0, VTIME > 0" 381In this case 382.Dv VTIME 383serves as an inter-byte timer and is activated after 384the first byte is received. Since it is an inter-byte timer, it is reset 385after a byte is received. The interaction between 386.Dv VMIN 387and 388.Dv VTIME 389is as 390follows: as soon as one byte is received, the inter-byte timer is 391started. If 392.Dv VMIN 393bytes are received before the inter-byte timer expires 394(remember that the timer is reset upon receipt of each byte), the read is 395satisfied. If the timer expires before 396.Dv VMIN 397bytes are received, the 398characters received to that point are returned to the user. Note that if 399.Dv VTIME 400expires at least one byte is returned because the timer would 401not have been enabled unless a byte was received. In this case 402.Pf \&( Dv VMIN 403> 0, 404.Dv VTIME 405> 0) the read blocks until the 406.Dv VMIN 407and 408.Dv VTIME 409mechanisms are 410activated by the receipt of the first byte, or a signal is received. If 411data is in the buffer at the time of the read(), the result is as 412if data had been received immediately after the read(). 413.Ss "Case B: VMIN > 0, VTIME = 0" 414In this case, since the value of 415.Dv VTIME 416is zero, the timer plays no role 417and only 418.Dv VMIN 419is significant. A pending read is not satisfied until 420.Dv VMIN 421bytes are received (i.e., the pending read blocks until 422.Dv VMIN 423bytes 424are received), or a signal is received. A program that uses this case to 425read record-based terminal 426.Dv I/O 427may block indefinitely in the read 428operation. 429.Ss "Case C: VMIN = 0, VTIME > 0" 430In this case, since 431.Dv VMIN 432= 0, 433.Dv VTIME 434no longer represents an inter-byte 435timer. It now serves as a read timer that is activated as soon as the 436read function is processed. A read is satisfied as soon as a single 437byte is received or the read timer expires. Note that in this case if 438the timer expires, no bytes are returned. If the timer does not 439expire, the only way the read can be satisfied is if a byte is received. 440In this case the read will not block indefinitely waiting for a byte; if 441no byte is received within 442.Dv VTIME Ns *0.1 443seconds after the read is initiated, 444the read returns a value of zero, having read no data. If data is 445in the buffer at the time of the read, the timer is started as if 446data had been received immediately after the read. 447.Ss Case D: VMIN = 0, VTIME = 0 448The minimum of either the number of bytes requested or the number of 449bytes currently available is returned without waiting for more 450bytes to be input. If no characters are available, read returns a 451value of zero, having read no data. 452.Ss Writing Data and Output Processing 453When a process writes one or more bytes to a terminal device file, they 454are processed according to the 455.Fa c_oflag 456field (see the 457.Sx "Output Modes 458section). The 459implementation may provide a buffering mechanism; as such, when a call to 460write() completes, all of the bytes written have been scheduled for 461transmission to the device, but the transmission will not necessarily 462have been completed. 463.\" See also .Sx "6.4.2" for the effects of 464.\" .Dv O_NONBLOCK 465.\" on write. 466.Ss Special Characters 467Certain characters have special functions on input or output or both. 468These functions are summarized as follows: 469.Bl -tag -width indent 470.It Dv INTR 471Special character on input and is recognized if the 472.Dv ISIG 473flag (see the 474.Sx "Local Modes" 475section) is enabled. Generates a 476.Dv SIGINT 477signal which is sent to all processes in the foreground 478process group for which the terminal is the controlling 479terminal. If 480.Dv ISIG 481is set, the 482.Dv INTR 483character is 484discarded when processed. 485.It Dv QUIT 486Special character on input and is recognized if the 487.Dv ISIG 488flag is enabled. Generates a 489.Dv SIGQUIT 490signal which is 491sent to all processes in the foreground process group 492for which the terminal is the controlling terminal. If 493.Dv ISIG 494is set, the 495.Dv QUIT 496character is discarded when 497processed. 498.It Dv ERASE 499Special character on input and is recognized if the 500.Dv ICANON 501flag is set. Erases the last character in the 502current line; see 503.Sx "Canonical Mode Input Processing" . 504It does not erase beyond 505the start of a line, as delimited by a 506.Dv NL , 507.Dv EOF , 508or 509.Dv EOL 510character. If 511.Dv ICANON 512is set, the 513.Dv ERASE 514character is 515discarded when processed. 516.It Dv KILL 517Special character on input and is recognized if the 518.Dv ICANON 519flag is set. Deletes the entire line, as 520delimited by a 521.Dv NL , 522.Dv EOF , 523or 524.Dv EOL 525character. If 526.Dv ICANON 527is set, the 528.Dv KILL 529character is discarded when processed. 530.It Dv EOF 531Special character on input and is recognized if the 532.Dv ICANON 533flag is set. When received, all the bytes 534waiting to be read are immediately passed to the 535process, without waiting for a newline, and the 536.Dv EOF 537is discarded. Thus, if there are no bytes waiting (that 538is, the 539.Dv EOF 540occurred at the beginning of a line), a byte 541count of zero is returned from the read(), 542representing an end-of-file indication. If 543.Dv ICANON 544is 545set, the 546.Dv EOF 547character is discarded when processed. 548.Dv NL 549Special character on input and is recognized if the 550.Dv ICANON 551flag is set. It is the line delimiter 552.Ql \&\en . 553.It Dv EOL 554Special character on input and is recognized if the 555.Dv ICANON 556flag is set. Is an additional line delimiter, 557like 558.Dv NL . 559.It Dv SUSP 560If the 561.Dv ISIG 562flag is enabled, receipt of the 563.Dv SUSP 564character causes a 565.Dv SIGTSTP 566signal to be sent to all processes in the 567foreground process group for which the terminal is the 568controlling terminal, and the 569.Dv SUSP 570character is 571discarded when processed. 572.It Dv STOP 573Special character on both input and output and is 574recognized if the 575.Dv IXON 576(output control) or 577.Dv IXOFF 578(input 579control) flag is set. Can be used to temporarily 580suspend output. It is useful with fast terminals to 581prevent output from disappearing before it can be read. 582If 583.Dv IXON 584is set, the 585.Dv STOP 586character is discarded when 587processed. 588.It Dv START 589Special character on both input and output and is 590recognized if the 591.Dv IXON 592(output control) or 593.Dv IXOFF 594(input 595control) flag is set. Can be used to resume output that 596has been suspended by a 597.Dv STOP 598character. If 599.Dv IXON 600is set, the 601.Dv START 602character is discarded when processed. 603.Dv CR 604Special character on input and is recognized if the 605.Dv ICANON 606flag is set; it is the 607.Ql \&\er , 608as denoted in the 609.Tn \&C 610Standard {2}. When 611.Dv ICANON 612and 613.Dv ICRNL 614are set and 615.Dv IGNCR 616is not set, this character is translated into a 617.Dv NL , 618and 619has the same effect as a 620.Dv NL 621character. 622.El 623.Pp 624The following special characters are extensions defined by this 625system and are not a part of 1003.1 termios. 626.Bl -tag -width indent 627.It Dv EOL2 628Secondary 629.Dv EOL 630character. Same function as 631.Dv EOL. 632.It Dv WERASE 633Special character on input and is recognized if the 634.Dv ICANON 635flag is set. Erases the last word in the current 636line according to one of two algorithms. If the 637.Dv ALTWERASE 638flag is not set, first any preceding whitespace is 639erased, and then the maximal sequence of non-whitespace 640characters. If 641.Dv ALTWERASE 642is set, first any preceding 643whitespace is erased, and then the maximal sequence 644of alphabetic/underscores or non alphabetic/underscores. 645As a special case in this second algorithm, the first previous 646non-whitespace character is skipped in determining 647whether the preceding word is a sequence of 648alphabetic/underscores. This sounds confusing but turns 649out to be quite practical. 650.It Dv REPRINT 651Special character on input and is recognized if the 652.Dv ICANON 653flag is set. Causes the current input edit line 654to be retyped. 655.It Dv DSUSP 656Has similar actions to the 657.Dv SUSP 658character, except that 659the 660.Dv SIGTSTP 661signal is delivered when one of the processes 662in the foreground process group issues a read() to the 663controlling terminal. 664.It Dv LNEXT 665Special character on input and is recognized if the 666.Dv IEXTEN 667flag is set. Receipt of this character causes the next 668character to be taken literally. 669.It Dv DISCARD 670Special character on input and is recognized if the 671.Dv IEXTEN 672flag is set. Receipt of this character toggles the flushing 673of terminal output. 674.It Dv STATUS 675Special character on input and is recognized if the 676.Dv ICANON 677flag is set. Receipt of this character causes a 678.Dv SIGINFO 679signal to be sent to the foreground process group of the 680terminal. Also, if the 681.Dv NOKERNINFO 682flag is not set, it 683causes the kernel to write a status message to the terminal 684that displays the current load average, the name of the 685command in the foreground, its process ID, the symbolic 686wait channel, the number of user and system seconds used, 687the percentage of cpu the process is getting, and the resident 688set size of the process. 689.El 690.Pp 691The 692.Dv NL 693and 694.Dv CR 695characters cannot be changed. 696The values for all the remaining characters can be set and are 697described later in the document under 698Special Control Characters. 699.Pp 700Special 701character functions associated with changeable special control characters 702can be disabled individually by setting their value to 703.Dv {_POSIX_VDISABLE}; 704see 705.Sx "Special Control Characters" . 706.Pp 707If two or more special characters have the same value, the function 708performed when that character is received is undefined. 709.Ss Modem Disconnect 710If a modem disconnect is detected by the terminal interface for a 711controlling terminal, and if 712.Dv CLOCAL 713is not set in the 714.Fa c_cflag 715field for 716the terminal, the 717.Dv SIGHUP 718signal is sent to the controlling 719process associated with the terminal. Unless other arrangements have 720been made, this causes the controlling process to terminate. 721Any subsequent call to the read() function returns the value zero, 722indicating end of file. Thus, processes that read a terminal 723file and test for end-of-file can terminate appropriately after a 724disconnect. 725.\" If the 726.\" .Er EIO 727.\" condition specified in 6.1.1.4 that applies 728.\" when the implementation supports job control also exists, it is 729.\" unspecified whether the 730.\" .Dv EOF 731.\" condition or the 732.\" .Pf [ Dv EIO 733.\" ] is returned. 734Any 735subsequent write() to the terminal device returns -1, with 736.Va errno 737set to 738.Er EIO , 739until the device is closed. 740.Sh General Terminal Interface 741.Ss Closing a Terminal Device File 742The last process to close a terminal device file causes any output 743to be sent to the device and any input to be discarded. Then, if 744.Dv HUPCL 745is set in the control modes, and the communications port supports a 746disconnect function, the terminal device performs a disconnect. 747.Ss Parameters That Can Be Set 748Routines that need to control certain terminal 749.Tn I/O 750characteristics 751do so by using the termios structure as defined in the header 752.Aq Pa termios.h . 753This structure contains minimally four scalar elements of bit flags 754and one array of special characters. The scalar flag elements are 755named: 756.Fa c_iflag , 757.Fa c_oflag , 758.Fa c_cflag , 759and 760.Fa c_lflag . 761The character array is named 762.Fa c_cc , 763and its maximum index is 764.Dv NCCS . 765.Ss Input Modes 766Values of the 767.Fa c_iflag 768field describe the basic 769terminal input control, and are composed of 770following masks: 771.Pp 772.Bl -tag -width IMAXBEL -offset indent -compact 773.It Dv IGNBRK 774/* ignore BREAK condition */ 775.It Dv BRKINT 776/* map BREAK to SIGINTR */ 777.It Dv IGNPAR 778/* ignore (discard) parity errors */ 779.It Dv PARMRK 780/* mark parity and framing errors */ 781.It Dv INPCK 782/* enable checking of parity errors */ 783.It Dv ISTRIP 784/* strip 8th bit off chars */ 785.It Dv INLCR 786/* map NL into CR */ 787.It Dv IGNCR 788/* ignore CR */ 789.It Dv ICRNL 790/* map CR to NL (ala CRMOD) */ 791.It Dv IXON 792/* enable output flow control */ 793.It Dv IXOFF 794/* enable input flow control */ 795.It Dv IXANY 796/* any char will restart after stop */ 797.It Dv IMAXBEL 798/* ring bell on input queue full */ 799.It Dv IUCLC 800/* translate upper case to lower case */ 801.El 802.Pp 803In the context of asynchronous serial data transmission, a break 804condition is defined as a sequence of zero-valued bits that continues for 805more than the time to send one byte. The entire sequence of zero-valued 806bits is interpreted as a single break condition, even if it continues for 807a time equivalent to more than one byte. In contexts other than 808asynchronous serial data transmission the definition of a break condition 809is implementation defined. 810.Pp 811If 812.Dv IGNBRK 813is set, a break condition detected on input is ignored, that 814is, not put on the input queue and therefore not read by any process. If 815.Dv IGNBRK 816is not set and 817.Dv BRKINT 818is set, the break condition flushes the 819input and output queues and if the terminal is the controlling terminal 820of a foreground process group, the break condition generates a 821single 822.Dv SIGINT 823signal to that foreground process group. If neither 824.Dv IGNBRK 825nor 826.Dv BRKINT 827is set, a break condition is read as a single 828.Ql \&\e0 , 829or if 830.Dv PARMRK 831is set, as 832.Ql \&\e377 , 833.Ql \&\e0 , 834.Ql \&\e0 . 835.Pp 836If 837.Dv IGNPAR 838is set, a byte with a framing or parity error (other than 839break) is ignored. 840.Pp 841If 842.Dv PARMRK 843is set, and 844.Dv IGNPAR 845is not set, a byte with a framing or parity 846error (other than break) is given to the application as the 847three-character sequence 848.Ql \&\e377 , 849.Ql \&\e0 , 850X, where 851.Ql \&\e377 , 852.Ql \&\e0 853is a two-character 854flag preceding each sequence and X is the data of the character received 855in error. To avoid ambiguity in this case, if 856.Dv ISTRIP 857is not set, a valid 858character of 859.Ql \&\e377 860is given to the application as 861.Ql \&\e377 , 862.Ql \&\e377 . 863If 864neither 865.Dv PARMRK 866nor 867.Dv IGNPAR 868is set, a framing or parity error (other than 869break) is given to the application as a single character 870.Ql \&\e0 . 871.Pp 872If 873.Dv INPCK 874is set, input parity checking is enabled. If 875.Dv INPCK 876is not set, 877input parity checking is disabled, allowing output parity generation 878without input parity errors. Note that whether input parity checking is 879enabled or disabled is independent of whether parity detection is enabled 880or disabled (see 881.Sx "Control Modes" ) . 882If parity detection is enabled but input 883parity checking is disabled, the hardware to which the terminal is 884connected recognizes the parity bit, but the terminal special file 885does not check whether this bit is set correctly or not. 886.Pp 887If 888.Dv ISTRIP 889is set, valid input bytes are first stripped to seven bits, 890otherwise all eight bits are processed. 891.Pp 892If 893.Dv INLCR 894is set, a received 895.Dv NL 896character is translated into a 897.Dv CR 898character. If 899.Dv IGNCR 900is set, a received 901.Dv CR 902character is ignored (not 903read). If 904.Dv IGNCR 905is not set and 906.Dv ICRNL 907is set, a received 908.Dv CR 909character is 910translated into a 911.Dv NL 912character. 913.Pp 914If 915.Dv IXON 916is set, start/stop output control is enabled. A received 917.Dv STOP 918character suspends output and a received 919.Dv START 920character 921restarts output. If 922.Dv IXANY 923is also set, then any character may 924restart output. When 925.Dv IXON 926is set, 927.Dv START 928and 929.Dv STOP 930characters are not 931read, but merely perform flow control functions. When 932.Dv IXON 933is not set, 934the 935.Dv START 936and 937.Dv STOP 938characters are read. 939.Pp 940If 941.Dv IXOFF 942is set, start/stop input control is enabled. The system shall 943transmit one or more 944.Dv STOP 945characters, which are intended to cause the 946terminal device to stop transmitting data, as needed to prevent the input 947queue from overflowing and causing the undefined behavior described in 948.Sx "Input Processing and Reading Data" , 949and shall transmit one or more 950.Dv START 951characters, which are 952intended to cause the terminal device to resume transmitting data, as 953soon as the device can continue transmitting data without risk of 954overflowing the input queue. The precise conditions under which 955.Dv STOP 956and 957START 958characters are transmitted are implementation defined. 959.Pp 960If 961.Dv IMAXBEL 962is set and the input queue is full, subsequent input shall cause an 963.Tn ASCII 964.Dv BEL 965character to be transmitted to 966the output queue. 967.Pp 968If 969.Dv IUCLC 970is set, characters will be translated from upper to lower case on 971input. 972.Pp 973The initial input control value after open() is implementation defined. 974.Ss Output Modes 975Values of the 976.Fa c_oflag 977field describe the basic terminal output control, 978and are composed of the following masks: 979.Pp 980.Bl -tag -width OXTABS -offset indent -compact 981.It Dv OPOST 982/* enable following output processing */ 983.It Dv ONLCR 984/* map NL to CR-NL (ala 985.Dv CRMOD) 986*/ 987.It Dv OXTABS 988/* expand tabs to spaces */ 989.It Dv ONOEOT 990/* discard 991.Dv EOT Ns 's 992.Ql \&^D 993on output) */ 994.It Dv OCRNL 995/* map CR to NL */ 996.It Dv OLCUC 997/* translate lower case to upper case */ 998.It Dv ONOCR 999/* No CR output at column 0 */ 1000.It Dv ONLRET 1001/* NL performs CR function */ 1002.El 1003.Pp 1004If 1005.Dv OPOST 1006is set, the remaining flag masks are interpreted as follows; 1007otherwise characters are transmitted without change. 1008.Pp 1009If 1010.Dv ONLCR 1011is set, newlines are translated to carriage return, linefeeds. 1012.Pp 1013If 1014.Dv OXTABS 1015is set, tabs are expanded to the appropriate number of 1016spaces (assuming 8 column tab stops). 1017.Pp 1018If 1019.Dv ONOEOT 1020is set, 1021.Tn ASCII 1022.Dv EOT Ns 's 1023are discarded on output. 1024.Pp 1025If 1026.Dv OCRNL 1027is set, carriage returns are translated to newlines. 1028.Pp 1029If 1030.Dv OLCUC 1031is set, lower case is translated to upper case on output. 1032.Pp 1033If 1034.Dv ONOCR 1035is set, no CR character is output when at column 0. 1036.Pp 1037If 1038.Dv ONLRET 1039is set, NL also performs CR on output, and reset current 1040column to 0. 1041.Ss Control Modes 1042Values of the 1043.Fa c_cflag 1044field describe the basic 1045terminal hardware control, and are composed of the 1046following masks. 1047Not all values 1048specified are supported by all hardware. 1049.Pp 1050.Bl -tag -width CRTSXIFLOW -offset indent -compact 1051.It Dv CSIZE 1052/* character size mask */ 1053.It Dv CS5 1054/* 5 bits (pseudo) */ 1055.It Dv CS6 1056/* 6 bits */ 1057.It Dv CS7 1058/* 7 bits */ 1059.It Dv CS8 1060/* 8 bits */ 1061.It Dv CSTOPB 1062/* send 2 stop bits */ 1063.It Dv CREAD 1064/* enable receiver */ 1065.It Dv PARENB 1066/* parity enable */ 1067.It Dv PARODD 1068/* odd parity, else even */ 1069.It Dv HUPCL 1070/* hang up on last close */ 1071.It Dv CLOCAL 1072/* ignore modem status lines */ 1073.It Dv CCTS_OFLOW 1074/* 1075.Dv CTS 1076flow control of output */ 1077.It Dv CRTSCTS 1078/* same as 1079.Dv CCTS_OFLOW 1080*/ 1081.It Dv CRTS_IFLOW 1082/* RTS flow control of input */ 1083.It Dv MDMBUF 1084/* flow control output via Carrier */ 1085.El 1086.Pp 1087The 1088.Dv CSIZE 1089bits specify the byte size in bits for both transmission and 1090reception. The 1091.Fa c_cflag 1092is masked with 1093.Dv CSIZE 1094and compared with the 1095values 1096.Dv CS5 , 1097.Dv CS6 , 1098.Dv CS7 , 1099or 1100.Dv CS8 . 1101This size does not include the parity bit, if any. If 1102.Dv CSTOPB 1103is set, two stop bits are used, otherwise one stop bit. For example, at 1104110 baud, two stop bits are normally used. 1105.Pp 1106If 1107.Dv CREAD 1108is set, the receiver is enabled. Otherwise, no character is 1109received. 1110Not all hardware supports this bit. In fact, this flag 1111is pretty silly and if it were not part of the 1112.Nm 1113specification 1114it would be omitted. 1115.Pp 1116If 1117.Dv PARENB 1118is set, parity generation and detection are enabled and a parity 1119bit is added to each character. If parity is enabled, 1120.Dv PARODD 1121specifies 1122odd parity if set, otherwise even parity is used. 1123.Pp 1124If 1125.Dv HUPCL 1126is set, the modem control lines for the port are lowered 1127when the last process with the port open closes the port or the process 1128terminates. The modem connection is broken. 1129.Pp 1130If 1131.Dv CLOCAL 1132is set, a connection does not depend on the state of the modem 1133status lines. If 1134.Dv CLOCAL 1135is clear, the modem status lines are 1136monitored. 1137.Pp 1138Under normal circumstances, a call to the open() function waits for 1139the modem connection to complete. However, if the 1140.Dv O_NONBLOCK 1141flag is set 1142or if 1143.Dv CLOCAL 1144has been set, the open() function returns 1145immediately without waiting for the connection. 1146.Pp 1147The 1148.Dv CCTS_OFLOW 1149.Pf ( Dv CRTSCTS ) 1150flag is currently unused. 1151.Pp 1152If 1153.Dv MDMBUF 1154is set then output flow control is controlled by the state 1155of Carrier Detect. 1156.Pp 1157If the object for which the control modes are set is not an asynchronous 1158serial connection, some of the modes may be ignored; for example, if an 1159attempt is made to set the baud rate on a network connection to a 1160terminal on another host, the baud rate may or may not be set on the 1161connection between that terminal and the machine it is directly connected 1162to. 1163.Ss Local Modes 1164Values of the 1165.Fa c_lflag 1166field describe the control of 1167various functions, and are composed of the following 1168masks. 1169.Pp 1170.Bl -tag -width NOKERNINFO -offset indent -compact 1171.It Dv ECHOKE 1172/* visual erase for line kill */ 1173.It Dv ECHOE 1174/* visually erase chars */ 1175.It Dv ECHO 1176/* enable echoing */ 1177.It Dv ECHONL 1178/* echo 1179.Dv NL 1180even if 1181.Dv ECHO 1182is off */ 1183.It Dv ECHOPRT 1184/* visual erase mode for hardcopy */ 1185.It Dv ECHOCTL 1186/* echo control chars as ^(Char) */ 1187.It Dv ISIG 1188/* enable signals 1189.Dv INTR , 1190.Dv QUIT , 1191.Dv [D]SUSP 1192*/ 1193.It Dv ICANON 1194/* canonicalize input lines */ 1195.It Dv ALTWERASE 1196/* use alternate 1197.Dv WERASE 1198algorithm */ 1199.It Dv IEXTEN 1200/* enable 1201.Dv DISCARD 1202and 1203.Dv LNEXT 1204*/ 1205.It Dv EXTPROC 1206/* external processing */ 1207.It Dv TOSTOP 1208/* stop background jobs from output */ 1209.It Dv FLUSHO 1210/* output being flushed (state) */ 1211.It Dv NOKERNINFO 1212/* no kernel output from 1213.Dv VSTATUS 1214*/ 1215.It Dv PENDIN 1216/* XXX retype pending input (state) */ 1217.It Dv NOFLSH 1218/* don't flush after interrupt */ 1219.It Dv XCASE 1220/* canonical upper/lower case */ 1221.El 1222.Pp 1223If 1224.Dv ECHO 1225is set, input characters are echoed back to the terminal. If 1226.Dv ECHO 1227is not set, input characters are not echoed. 1228.Pp 1229If 1230.Dv ECHOE 1231and 1232.Dv ICANON 1233are set, the 1234.Dv ERASE 1235character causes the terminal 1236to erase the last character in the current line from the display, if 1237possible. If there is no character to erase, an implementation may echo 1238an indication that this was the case or do nothing. 1239.Pp 1240If 1241.Dv ECHOK 1242and 1243.Dv ICANON 1244are set, the 1245.Dv KILL 1246character causes 1247the current line to be discarded and the system echoes the 1248.Ql \&\en 1249character after the 1250.Dv KILL 1251character. 1252.Pp 1253If 1254.Dv ECHOKE 1255and 1256.Dv ICANON 1257are set, the 1258.Dv KILL 1259character causes 1260the current line to be discarded and the system causes 1261the terminal 1262to erase the line from the display. 1263.Pp 1264If 1265.Dv ECHOPRT 1266and 1267.Dv ICANON 1268are set, the system assumes 1269that the display is a printing device and prints a 1270backslash and the erased characters when processing 1271.Dv ERASE 1272characters, followed by a forward slash. 1273.Pp 1274If 1275.Dv ECHOCTL 1276is set, the system echoes control characters 1277in a visible fashion using a caret followed by the control character. 1278.Pp 1279If 1280.Dv ALTWERASE 1281is set, the system uses an alternative algorithm 1282for determining what constitutes a word when processing 1283.Dv WERASE 1284characters (see 1285.Dv WERASE ) . 1286.Pp 1287If 1288.Dv ECHONL 1289and 1290.Dv ICANON 1291are set, the 1292.Ql \&\en 1293character echoes even if 1294.Dv ECHO 1295is not set. 1296.Pp 1297If 1298.Dv ICANON 1299is set, canonical processing is enabled. This enables the 1300erase and kill edit functions, and the assembly of input characters into 1301lines delimited by 1302.Dv NL, 1303.Dv EOF , 1304and 1305.Dv EOL, 1306as described in 1307.Sx "Canonical Mode Input Processing" . 1308.Pp 1309If 1310.Dv ICANON 1311is not set, read requests are satisfied directly from the input 1312queue. A read is not satisfied until at least 1313.Dv VMIN 1314bytes have been 1315received or the timeout value 1316.Dv VTIME 1317expired between bytes. The time value 1318represents tenths of seconds. See 1319.Sx "Noncanonical Mode Input Processing" 1320for more details. 1321.Pp 1322If 1323.Dv ISIG 1324is set, each input character is checked against the special 1325control characters 1326.Dv INTR , 1327.Dv QUIT , 1328and 1329.Dv SUSP 1330(job control only). If an input 1331character matches one of these control characters, the function 1332associated with that character is performed. If 1333.Dv ISIG 1334is not set, no 1335checking is done. Thus these special input functions are possible only 1336if 1337.Dv ISIG 1338is set. 1339.Pp 1340If 1341.Dv IEXTEN 1342is set, implementation-defined functions are recognized 1343from the input data. How 1344.Dv IEXTEN 1345being set 1346interacts with 1347.Dv ICANON , 1348.Dv ISIG , 1349.Dv IXON , 1350or 1351.Dv IXOFF 1352is implementation defined. 1353If 1354.Dv IEXTEN 1355is not set, then 1356implementation-defined functions are not recognized, and the 1357corresponding input characters are not processed as described for 1358.Dv ICANON , 1359.Dv ISIG , 1360.Dv IXON , 1361and 1362.Dv IXOFF . 1363.Pp 1364If 1365.Dv NOFLSH 1366is set, the normal flush of the input and output queues 1367associated with the 1368.Dv INTR , 1369.Dv QUIT , 1370and 1371.Dv SUSP 1372characters 1373are not be done. 1374.Pp 1375If 1376.Dv XCASE 1377and 1378.Dv ICANON 1379is set, an upper case character is preserved on input if prefixed by 1380a \\ character. In addition, this prefix is added to upper case 1381characters on output. 1382.Pp 1383In addition, the following special character translations are in effect: 1384.Pp 1385.Bl -column "for:" "use:" -offset indent -compact 1386.It Em "for: use:" 1387.It Dv ` Ta \&\e' 1388.It Dv | Ta \&\e! 1389.It Dv ~ Ta \&\e^ 1390.It Dv { Ta \&\e( 1391.It Dv } Ta \&\e) 1392.It Dv \&\e Ta \&\e\e 1393.El 1394.Pp 1395If 1396.Dv TOSTOP 1397is set, the signal 1398.Dv SIGTTOU 1399is sent to the process group of a process that tries to write to 1400its controlling terminal if it is not in the foreground process group for 1401that terminal. This signal, by default, stops the members of the process 1402group. Otherwise, the output generated by that process is output to the 1403current output stream. Processes that are blocking or ignoring 1404.Dv SIGTTOU 1405signals are excepted and allowed to produce output and the 1406.Dv SIGTTOU 1407signal 1408is not sent. 1409.Pp 1410If 1411.Dv NOKERNINFO 1412is set, the kernel does not produce a status message 1413when processing 1414.Dv STATUS 1415characters (see 1416.Dv STATUS ) . 1417.Ss Special Control Characters 1418The special control characters values are defined by the array 1419.Fa c_cc . 1420This table lists the array index, the corresponding special character, 1421and the system default value. For an accurate list of 1422the system defaults, consult the header file 1423.Aq Pa ttydefaults.h . 1424.Pp 1425.Bl -column "Index Name" "Special Character" -offset indent -compact 1426.It Em "Index Name Special Character Default Value" 1427.It Dv VEOF Ta EOF Ta \&^D 1428.It Dv VEOL Ta EOL Ta _POSIX_VDISABLE 1429.It Dv VEOL2 Ta EOL2 Ta _POSIX_VDISABLE 1430.It Dv VERASE Ta ERASE Ta \&^? Ql \&\e177 1431.It Dv VWERASE Ta WERASE Ta \&^W 1432.It Dv VKILL Ta KILL Ta \&^U 1433.It Dv VREPRINT Ta REPRINT Ta \&^R 1434.It Dv VINTR Ta INTR Ta \&^C 1435.It Dv VQUIT Ta QUIT Ta \&^\e\e Ql \&\e34 1436.It Dv VSUSP Ta SUSP Ta \&^Z 1437.It Dv VDSUSP Ta DSUSP Ta \&^Y 1438.It Dv VSTART Ta START Ta \&^Q 1439.It Dv VSTOP Ta STOP Ta \&^S 1440.It Dv VLNEXT Ta LNEXT Ta \&^V 1441.It Dv VDISCARD Ta DISCARD Ta \&^O 1442.It Dv VMIN Ta --- Ta \&1 1443.It Dv VTIME Ta --- Ta \&0 1444.It Dv VSTATUS Ta STATUS Ta \&^T 1445.El 1446.Pp 1447If the 1448value of one of the changeable special control characters (see 1449.Sx "Special Characters" ) 1450is 1451.Dv {_POSIX_VDISABLE} , 1452that function is disabled; that is, no input 1453data is recognized as the disabled special character. 1454If 1455.Dv ICANON 1456is 1457not set, the value of 1458.Dv {_POSIX_VDISABLE} 1459has no special meaning for the 1460.Dv VMIN 1461and 1462.Dv VTIME 1463entries of the 1464.Fa c_cc 1465array. 1466.Pp 1467The initial values of the flags and control characters 1468after open() is set according to 1469the values in the header 1470.Aq Pa sys/ttydefaults.h . 1471.Sh SEE ALSO 1472.Xr tcgetattr 3 , 1473.Xr tcsetattr 3 1474