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