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