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