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