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