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