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