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