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