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