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