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