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