1.\" Copyright (c) 1991, 1992 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.roff% 5.\" 6.\" @(#)termios.4 5.4 (Berkeley) 01/19/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 to 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 mereley 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 recieved 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.Br 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 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 skippied 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 forground 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 return 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 . The character array 730is 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 three- 814character 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 character is translated into a 863.Dv CR 864character. If 865.Dv IGNCR 866is set, a received 867.Dv CR 868character is ignored (not 869read). If 870.Dv IGNCR 871is not set and 872.Dv ICRNL 873is set, a received 874.Dv CR 875character is 876translated into a 877.Dv NL 878character. 879.Pp 880If 881.Dv IXON 882is set, start/stop output control is enabled. A received 883.Dv STOP 884character suspends output and a received 885.Dv START 886character 887restarts output. If 888.Dv IXANY 889is also set, then any character may 890restart output. When 891.Dv IXON 892is set, 893.Dv START 894and 895.Dv STOP 896characters are not 897read, but merely perform flow control functions. When 898.Dv IXON 899is not set, 900the 901.Dv START 902and 903.Dv STOP 904characters are read. 905.Pp 906If 907.Dv IXOFF 908is set, start/stop input control is enabled. The system shall 909transmit one or more 910.Dv STOP 911characters, which are intended to cause the 912terminal device to stop transmitting data, as needed to prevent the input 913queue from overflowing and causing the undefined behavior described in 914.Sx "Input Processing and Reading Data" , 915and shall transmit one or more 916.Dv START 917characters, which are 918intended to cause the terminal device to resume transmitting data, as 919soon as the device can continue transmitting data without risk of 920overflowing the input queue. The precise conditions under which 921.Dv STOP 922and 923START 924characters are transmitted are implementation defined. 925.Pp 926If 927.Dv IMAXBEL 928is set and the input queue is full, subsequent input 929shall causes an 930.Tn ASCII 931.Dv BEL 932character to be transmitted to the 933the output queue. 934.Pp 935The initial input control value after open() is implementation defined. 936.Ss Output Modes 937Values of the 938.Fa c_oflag 939field describe the basic terminal output control, 940and are composed of the following masks: 941.Pp 942.Bl -tag -width OXTABS -offset indent -compact 943.It Dv OPOST 944/* enable following output processing */ 945.It Dv ONLCR 946/* map NL to CR-NL (ala 947.Dv CRMOD) 948*/ 949.It Dv OXTABS 950/* expand tabs to spaces */ 951.It Dv ONOEOT 952/* discard 953.Dv EOT Ns 's 954.Ql \&^D 955on output) */ 956.El 957.Pp 958If 959.Dv OPOST 960is set, the remaining flag masks are interpreted as follows; 961otherwise characters are transmitted without change. 962.Pp 963If 964.Dv ONLCR 965is set, newlines are translated to carriage return, linefeeds. 966.Pp 967If 968.Dv OXTABS 969is set, tabs are expanded to the appropiate number of 970spaces (assuming 8 column tab stops). 971.Pp 972If 973.Dv ONOEOT 974is set, 975.Tn ASCII 976.Dv EOT NS 's 977are discarded on output. 978.Ss Control Modes 979Values of the 980.Fa c_cflag 981field describe the basic 982terminal hardware control, and are composed of the 983the following masks. 984Not all values 985specified are supported by all hardware. 986.Pp 987.Bl -tag -width CRTSXIFLOW -offset indent -compact 988.It Dv CSIZE 989/* character size mask */ 990.It Dv CS5 991/* 5 bits (pseudo) */ 992.It Dv CS6 993/* 6 bits */ 994.It Dv CS7 995/* 7 bits */ 996.It Dv CS8 997/* 8 bits */ 998.It Dv CSTOPB 999/* send 2 stop bits */ 1000.It Dv CREAD 1001/* enable receiver */ 1002.It Dv PARENB 1003/* parity enable */ 1004.It Dv PARODD 1005/* odd parity, else even */ 1006.It Dv HUPCL 1007/* hang up on last close */ 1008.It Dv CLOCAL 1009/* ignore modem status lines */ 1010.It Dv CCTS_OFLOW 1011/* 1012.Dv CTS 1013flow control of output */ 1014.It Dv CRTSCTS 1015/* same as 1016.Dv CCTS_OFLOW 1017*/ 1018.It Dv CRTS_IFLOW 1019/* RTS flow control of input */ 1020.It Dv MDMBUF 1021/* flow control output via Carrier */ 1022.El 1023.Pp 1024The 1025.Dv CSIZE 1026bits specify the byte size in bits for both transmission and 1027reception. The 1028.Fa c_cflag 1029is masked with 1030.Dv CSIZE 1031and compared with the 1032values 1033.Dv CS5 , 1034.Dv CS6 , 1035.Dv CS7 , 1036or 1037.Dv CS8 . 1038This size does not include the parity bit, if any. If 1039.Dv CSTOPB 1040is set, two stop bits are used, otherwise one stop bit. For example, at 1041110 baud, two stop bits are normally used. 1042.Pp 1043If 1044.Dv CREAD 1045is set, the receiver is enabled. Otherwise, no characters shall 1046be received. Not all hardware supports this bit. In fact, this flag 1047is pretty silly and if it were not part of the 1048.Nm termios 1049specification 1050it would be ommitted. 1051.Pp 1052If 1053.Dv PARENB 1054is set, parity generation and detection is enabled and a parity 1055bit is added to each character. If parity is enabled, 1056.Dv PARODD 1057specifies 1058odd parity if set, otherwise even parity is used. 1059.Pp 1060If 1061.Dv HUPCL 1062is set, the modem control lines for the port shall be lowered 1063when the last process with the port open closes the port or the process 1064terminates. The modem connection shall be broken. 1065.Pp 1066If 1067.Dv CLOCAL 1068is set, a connection does not depend on the state of the modem 1069status lines. If 1070.Dv CLOCAL 1071is clear, the modem status lines shall be 1072monitored. 1073.Pp 1074Under normal circumstances, a call to the open() function shall wait for 1075the modem connection to complete. However, if the 1076.Dv O_NONBLOCK 1077flag is set 1078or if 1079.Dv CLOCAL 1080has been set, the open() function shall return 1081immediately without waiting for the connection. 1082.Pp 1083The 1084.Dv CCTS_OFLOW 1085.Pf ( Dv CRTSCTS ) 1086flag is currently unused. 1087.Pp 1088If 1089.Dv MDMBUF 1090is set then output flow control is controlled by the state 1091of Carrier Detect. 1092.Pp 1093If the object for which the control modes are set is not an asynchronous 1094serial connection, some of the modes may be ignored; for example, if an 1095attempt is made to set the baud rate on a network connection to a 1096terminal on another host, the baud rate may or may not be set on the 1097connection between that terminal and the machine it is directly connected 1098to. 1099.Ss Local Modes 1100Values of the c_lflag field describe the control of 1101various functions, and are composed of the following 1102masks. 1103.Pp 1104.Bl -tag -width NOKERNINFO -offset indent -compact 1105.It Dv ECHOKE 1106/* visual erase for line kill */ 1107.It Dv ECHOE 1108/* visually erase chars */ 1109.It Dv ECHO 1110/* enable echoing */ 1111.It Dv ECHONL 1112/* echo 1113.Dv NL 1114even if 1115.Dv ECHO 1116is off */ 1117.It Dv ECHOPRT 1118/* visual erase mode for hardcopy */ 1119.It Dv ECHOCTL 1120/* echo control chars as ^(Char) */ 1121.It Dv ISIG 1122/* enable signals 1123.Dv INTR , 1124.Dv QUIT , 1125.Dv [D]SUSP 1126*/ 1127.It Dv ICANON 1128/* canonicalize input lines */ 1129.It Dv ALTWERASE 1130/* use alternate 1131.Dv WERASE 1132algorithm */ 1133.It Dv IEXTEN 1134/* enable 1135.Dv DISCARD 1136and 1137.Dv LNEXT 1138*/ 1139.It Dv EXTPROC 1140/* external processing */ 1141.It Dv TOSTOP 1142/* stop background jobs from output */ 1143.It Dv FLUSHO 1144/* output being flushed (state) */ 1145.It Dv NOKERNINFO 1146/* no kernel output from 1147.Dv VSTATUS 1148*/ 1149.It Dv PENDIN 1150/* XXX retype pending input (state) */ 1151.It Dv NOFLSH 1152/* don't flush after interrupt */ 1153.El 1154.Pp 1155If 1156.Dv ECHO 1157is set, input characters are echoed back to the terminal. If 1158.Dv ECHO 1159is not set, input characters are not echoed. 1160.Pp 1161If 1162.Dv ECHOE 1163and 1164.Dv ICANON 1165are set, the 1166.Dv ERASE 1167character shall cause the terminal 1168to erase the last character in the current line from the display, if 1169possible. If there is no character to erase, an implementation may echo 1170an indication that this was the case or do nothing. 1171.Pp 1172If 1173.Dv ECHOK 1174and 1175.Dv ICANON 1176are set, the 1177.Dv KILL 1178character shall 1179cause the current line to be discarded and the system shall 1180echo the 1181.Ql \&\en 1182character after the 1183.Dv KILL 1184character. 1185.Pp 1186If 1187.Dv ECHOKE 1188and 1189.Dv ICANON 1190are set, the 1191.Dv KILL 1192character shall cause 1193the current line to be discarded and the system shall cause 1194the terminal 1195to erase the line from the display. 1196.Pp 1197If 1198.Dv ECHOPRT 1199and 1200.Dv ICANON 1201are set, the system shall assume 1202that the display is a printing device and shall print a 1203backslash and the erased characters when processing 1204.Dv ERASE 1205characters, followed by a forward slash. 1206.Pp 1207If 1208.Dv ECHOCTL 1209is set, the system shall echo control characters 1210in a visible fashion using a carrot followed by the control character. 1211.Pp 1212If 1213.Dv ALTWERASE 1214is set, the system will use an alternative algorithm 1215for determining what constitutes a word when processing 1216.Dv WERASE 1217characters (see 1218.Dv WERASE ) . 1219.Pp 1220If 1221.Dv ECHONL 1222and 1223.Dv ICANON 1224are set, the 1225.Ql \&\en 1226character shall be echoed even if 1227.Dv ECHO 1228is not set. 1229.Pp 1230If 1231.Dv ICANON 1232is set, canonical processing is enabled. This enables the 1233erase and kill edit functions, and the assembly of input characters into 1234lines delimited by 1235.Dv NL, 1236.Dv EOF , 1237and 1238.Dv EOL, 1239as described in 1240.Sx "Canonical Mode Input Processing" . 1241.Pp 1242If 1243.Dv ICANON 1244is not set, read requests are satisfied directly from the input 1245queue. A read shall not be satisfied until at least 1246.Dv MIN 1247bytes have been 1248received or the timeout value 1249.Dv TIME 1250expired between bytes. The time value 1251represents tenths of seconds. See 1252.Sx "Noncanonical Mode Input Processing" 1253for more details. 1254.Pp 1255If 1256.Dv ISIG 1257is set, each input character is checked against the special 1258control characters 1259.Dv INTR , 1260.Dv QUIT , 1261and 1262.Dv SUSP 1263(job control only). If an input 1264character matches one of these control characters, the function 1265associated with that character is performed. If 1266.Dv ISIG 1267is not set, no 1268checking is done. Thus these special input functions are possible only 1269if 1270.Dv ISIG 1271is set. 1272.Pp 1273If 1274.Dv IEXTEN 1275is set, implementation-defined functions shall be recognized 1276from the input data. It is implementation defined how 1277.Dv IEXTEN 1278being set 1279interacts with 1280.Dv ICANON , 1281.Dv ISIG , 1282.Dv IXON , 1283or 1284.Dv IXOFF . 1285If 1286.Dv IEXTEN 1287is not set, then 1288implementation-defined functions shall not be recognized, and the 1289corresponding input characters shall be processed as described for 1290.Dv ICANON , 1291.Dv ISIG , 1292.Dv IXON , 1293and 1294.Dv IXOFF . 1295.Pp 1296If 1297.Dv NOFLSH 1298is set, the normal flush of the input and output queues 1299associated with the 1300.Dv INTR , 1301.Dv QUIT , 1302and 1303.Dv SUSP 1304characters 1305shall not be done. 1306.Pp 1307If 1308.Dv TOSTOP 1309is set, the signal 1310.Dv SIGTTOU 1311is sent to the process group of a process that tries to write to 1312its controlling terminal if it is not in the foreground process group for 1313that terminal. This signal, by default, stops the members of the process 1314group. Otherwise, the output generated by that process is output to the 1315current output stream. Processes that are blocking or ignoring 1316.Dv SIGTTOU 1317signals are excepted and allowed to produce output and the 1318.Dv SIGTTOU 1319signal 1320is not sent. 1321.Pp 1322If 1323.Dv NOKERNINFO 1324is set, the kernel shall not produce a status message 1325when processing 1326.Dv STATUS 1327characters (see 1328.Dv STATUS ) . 1329.Ss Special Control Characters 1330The special control characters values are defined by the array c_cc. 1331This table lists the array index, the corresponding special character, 1332and the system default value. For an accurate list of 1333the system defaults, consult the header file 1334.Aq Pa ttydefaults.h . 1335.Pp 1336.Bl -column "Index Name" "Special Character" -offset indent -compact 1337.It Em "Index Name Special Character Default Value" 1338.It Dv VEOF Ta EOF Ta \&^D 1339.It Dv VEOL Ta EOL Ta _POSIX_VDISABLE 1340.It Dv VEOL2 Ta EOL2 Ta _POSIX_VDISABLE 1341.It Dv VERASE Ta ERASE Ta \&^? Ql \&\e177 1342.It Dv VWERASE Ta WERASE Ta \&^W 1343.It Dv VKILL Ta KILL Ta \&^U 1344.It Dv VREPRINT Ta REPRINT Ta \&^R 1345.It Dv VINTR Ta INTR Ta \&^C 1346.It Dv VQUIT Ta QUIT Ta \&^\e\e Ql \&\e34 1347.It Dv VSUSP Ta SUSP Ta \&^Z 1348.It Dv VDSUSP Ta DSUSP Ta \&^Y 1349.It Dv VSTART Ta START Ta \&^Q 1350.It Dv VSTOP Ta STOP Ta \&^S 1351.It Dv VLNEXT Ta LNEXT Ta \&^V 1352.It Dv VDISCARD Ta DISCARD Ta \&^O 1353.It Dv VMIN Ta --- Ta \&1 1354.It Dv VTIME Ta --- Ta \&0 1355.It Dv VSTATUS Ta STATUS Ta \&^T 1356.El 1357.Pp 1358If the 1359value of one of the changeable special control characters (see 1360.Sx "Special Characters" ) 1361is 1362.Dv {_POSIX_VDISABLE} , 1363that function shall be disabled; that is, no input 1364data shall be recognized as the disabled special character. 1365If 1366.Dv ICANON 1367is 1368not set, the value of 1369.Dv {_POSIX_VDISABLE} 1370has no special meaning for the 1371.Dv VMIN 1372and 1373.Dv VTIME 1374entries of the 1375.Fa c_cc 1376array. 1377.Pp 1378The initial values of the flags and control characters 1379after open() is set according to 1380the values in the header 1381.Aq Pa sys/ttydefaults.h . 1382