xref: /freebsd/share/man/man4/termios.4 (revision 734e82fe33aa764367791a7d603b383996c6b40b)
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.\"	@(#)termios.4	8.4 (Berkeley) 4/19/94
29.\"
30.Dd June 28, 2020
31.Dt TERMIOS 4
32.Os
33.Sh NAME
34.Nm termios
35.Nd general terminal line discipline
36.Sh SYNOPSIS
37.In termios.h
38.Sh DESCRIPTION
39This describes a general terminal line discipline that is
40supported on tty asynchronous communication ports.
41.Ss Opening a Terminal Device File
42When a terminal file is opened, it normally causes the process to wait
43until a connection is established.
44For most hardware, the presence
45of a connection is indicated by the assertion of the hardware
46.Dv CARRIER
47line.
48If the termios structure associated with the terminal file has the
49.Dv CLOCAL
50flag set in the cflag, or if the
51.Dv O_NONBLOCK
52flag is set
53in the
54.Xr open 2
55call, then the open will succeed even without
56a connection being present.
57In practice, applications
58seldom open these files; they are opened by special programs, such
59as
60.Xr getty 8 ,
61and become
62an application's standard input, output, and error files.
63.Ss Job Control in a Nutshell
64Every process is associated with a particular process group and session.
65The grouping is hierarchical: every member of a particular process group is a
66member of the same session.
67This structuring is used in managing groups
68of related processes for purposes of
69.\" .Gw "job control" ;
70.Em "job control" ;
71that is, the
72ability from the keyboard (or from program control) to simultaneously
73stop or restart
74a complex command (a command composed of one or more related
75processes).
76The grouping into process groups allows delivering
77of signals that stop or start the group as a whole, along with
78arbitrating which process group has access to the single controlling
79terminal.
80The grouping at a higher layer into sessions is to restrict
81the job control related signals and system calls to within processes
82resulting from a particular instance of a
83.Dq login .
84Typically, a session
85is created when a user logs in, and the login terminal is setup
86to be the controlling terminal; all processes spawned from that
87login shell are in the same session, and inherit the controlling
88terminal.
89.Pp
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.
94A set of processes in the same process group
95is collectively referred to as a
96.Dq job .
97When the foreground process
98group of the terminal is the same as the process group of a particular
99job, that job is said to be in the
100.Dq foreground .
101When the process group of the terminal is different from the process group of
102a job (but is still the controlling terminal), that job is said
103to be in the
104.Dq background .
105Normally the
106shell reads a command and starts the job that implements that
107command.
108If the command is to be started in the foreground (typical), it
109sets the process group of the terminal to the process group
110of the started job, waits for the job to complete, and then
111sets the process group of the terminal back to its own process
112group (it puts itself into the foreground).
113If the job is to
114be started in the background (as denoted by the shell operator "&"),
115it never changes the process group of the terminal and does not
116wait for the job to complete (that is, it immediately attempts to read the next
117command).
118If the job is started in the foreground, the user may
119type a key (usually
120.Ql \&^Z )
121which generates the terminal stop signal
122.Pq Dv SIGTSTP
123and has the effect of stopping the entire job.
124The shell will notice that the job stopped, and will resume running after
125placing itself in the foreground.
126The shell also has commands for placing stopped jobs in the background,
127and for placing stopped or background jobs into the foreground.
128.Ss Orphaned Process Groups
129An orphaned process group is a process group that has no process
130whose parent is in a different process group, yet is in the same
131session.
132Conceptually it means a process group that does not have
133a parent that could do anything if it were to be stopped.
134For example,
135the initial login shell is typically in an orphaned process group.
136Orphaned process groups are immune to keyboard generated stop
137signals and job control signals resulting from reads or writes to the
138controlling terminal.
139.Ss The Controlling Terminal
140A terminal may belong to a process as its controlling terminal.
141Each
142process of a session that has a controlling terminal has the same
143controlling terminal.
144A terminal may be the controlling terminal for at
145most one session.
146The controlling terminal for a session is allocated by
147the session leader by issuing the
148.Dv TIOCSCTTY
149ioctl.
150A controlling terminal
151is never acquired by merely opening a terminal device file.
152When a controlling terminal becomes
153associated with a session, its foreground process group is set to
154the process group of the session leader.
155.Pp
156The controlling terminal is inherited by a child process during a
157.Xr fork 2
158function call.
159A process relinquishes its controlling terminal when it
160creates a new session with the
161.Xr setsid 2
162function; other processes
163remaining in the old session that had this terminal as their controlling
164terminal continue to have it.
165A process does not relinquish its
166controlling terminal simply by closing all of its file descriptors
167associated with the controlling terminal if other processes continue to
168have it open.
169.Pp
170When a controlling process terminates, the controlling terminal is
171disassociated from the current session, allowing it to be acquired by a
172new session leader.
173Subsequent access to the terminal by other processes
174in the earlier session will be denied, with attempts to access the
175terminal treated as if modem disconnect had been sensed.
176.Ss Terminal Access Control
177If a process is in the foreground process group of its controlling
178terminal, read operations are allowed.
179Any attempts by a process
180in a background process group to read from its controlling terminal
181causes a
182.Dv SIGTTIN
183signal to be sent to
184the process's group
185unless one of the
186following special cases apply: if the reading process is ignoring or
187blocking the
188.Dv SIGTTIN
189signal, or if the process group of the reading
190process is orphaned, the
191.Xr read 2
192returns -1 with
193.Va errno
194set to
195.Er EIO
196and no
197signal is sent.
198The default action of the
199.Dv SIGTTIN
200signal is to stop the
201process to which it is sent.
202.Pp
203If a process is in the foreground process group of its controlling
204terminal, write operations are allowed.
205Attempts by a process in a background process group to write to its
206controlling terminal will cause the process group to be sent a
207.Dv SIGTTOU
208signal unless one of the following special cases apply: if
209.Dv TOSTOP
210is not
211set, or if
212.Dv TOSTOP
213is set and the process is ignoring or blocking the
214.Dv SIGTTOU
215signal, the process is allowed to write to the terminal and the
216.Dv SIGTTOU
217signal is not sent.
218If
219.Dv TOSTOP
220is set, and the process group of
221the writing process is orphaned, and the writing process is not ignoring
222or blocking
223.Dv SIGTTOU ,
224the
225.Xr write 2
226returns -1 with
227errno set to
228.Er EIO
229and no signal is sent.
230.Pp
231Certain calls that set terminal parameters are treated in the same
232fashion as write, except that
233.Dv TOSTOP
234is ignored; that is, the effect is
235identical to that of terminal writes when
236.Dv TOSTOP
237is set.
238.Ss Input Processing and Reading Data
239A terminal device associated with a terminal device file may operate in
240full-duplex mode, so that data may arrive even while output is occurring.
241Each terminal device file has associated with it an input queue, into
242which incoming data is stored by the system before being read by a
243process.
244The system imposes a limit,
245.Pf \&{ Dv MAX_INPUT Ns \&} ,
246on the number of
247bytes that may be stored in the input queue.
248The behavior of the system
249when this limit is exceeded depends on the setting of the
250.Dv IMAXBEL
251flag in the termios
252.Fa c_iflag .
253If this flag is set, the terminal
254is sent an
255.Tn ASCII
256.Dv BEL
257character each time a character is received
258while the input queue is full.
259Otherwise, the input queue is flushed upon receiving the character.
260.Pp
261Two general kinds of input processing are available, determined by
262whether the terminal device file is in canonical mode or noncanonical
263mode.
264Additionally,
265input characters are processed according to the
266.Fa c_iflag
267and
268.Fa c_lflag
269fields.
270Such processing can include echoing, which
271in general means transmitting input characters immediately back to the
272terminal when they are received from the terminal.
273This is useful for terminals that can operate in full-duplex mode.
274.Pp
275The manner in which data is provided to a process reading from a terminal
276device file is dependent on whether the terminal device file is in
277canonical or noncanonical mode.
278.Pp
279Another dependency is whether the
280.Dv O_NONBLOCK
281flag is set by
282.Xr open 2
283or
284.Xr fcntl 2 .
285If the
286.Dv O_NONBLOCK
287flag is clear, then the read request is
288blocked until data is available or a signal has been received.
289If the
290.Dv O_NONBLOCK
291flag is set, then the read request is completed, without
292blocking, in one of three ways:
293.Bl -enum -offset indent
294.It
295If there is enough data available to satisfy the entire request,
296and the read completes successfully the number of
297bytes read is returned.
298.It
299If there is not enough data available to satisfy the entire
300request, and the read completes successfully, having read as
301much data as possible, the number of bytes read is returned.
302.It
303If there is no data available, the read returns -1, with
304errno set to
305.Er EAGAIN .
306.El
307.Pp
308When data is available depends on whether the input processing mode is
309canonical or noncanonical.
310.Ss Canonical Mode Input Processing
311In canonical mode input processing, terminal input is processed in units
312of lines.
313A line is delimited by a newline
314.Ql \&\en
315character, an end-of-file
316.Pq Dv EOF
317character, or an end-of-line
318.Pq Dv EOL
319character.
320See the
321.Sx "Special Characters"
322section for
323more information on
324.Dv EOF
325and
326.Dv EOL .
327This means that a read request will
328not return until an entire line has been typed, or a signal has been
329received.
330Also, no matter how many bytes are requested in the read call,
331at most one line is returned.
332It is not, however, necessary to
333read a whole line at once; any number of bytes, even one, may be
334requested in a read without losing information.
335.Pp
336.Pf \&{ Dv MAX_CANON Ns \&}
337is a limit on the
338number of bytes in a line.
339The behavior of the system when this limit is
340exceeded is the same as when the input queue limit
341.Pf \&{ Dv MAX_INPUT Ns \&} ,
342is exceeded.
343.Pp
344Erase and kill processing occur when either of two special characters,
345the
346.Dv ERASE
347and
348.Dv KILL
349characters (see the
350.Sx "Special Characters"
351section), is received.
352This processing affects data in the input queue that has not yet been
353delimited by a newline
354.Dv NL ,
355.Dv EOF ,
356or
357.Dv EOL
358character.
359This un-delimited
360data makes up the current line.
361The
362.Dv ERASE
363character deletes the last
364character in the current line, if there is any.
365The
366.Dv KILL
367character
368deletes all data in the current line, if there is any.
369The
370.Dv ERASE
371and
372.Dv KILL
373characters have no effect if there is no data in the current line.
374The
375.Dv ERASE
376and
377.Dv KILL
378characters themselves are not placed in the input
379queue.
380.Ss Noncanonical Mode Input Processing
381In noncanonical mode input processing, input bytes are not assembled into
382lines, and erase and kill processing does not occur.
383The values of the
384.Dv VMIN
385and
386.Dv VTIME
387members of the
388.Fa c_cc
389array are used to determine how to
390process the bytes received.
391.Pp
392.Dv MIN
393represents the minimum number of bytes that should be received when
394the
395.Xr read 2
396function successfully returns.
397.Dv TIME
398is a timer of 0.1 second
399granularity that is used to time out bursty and short term data
400transmissions.
401If
402.Dv MIN
403is greater than
404.Dv \&{ Dv MAX_INPUT Ns \&} ,
405the response to the
406request is undefined.
407The four possible values for
408.Dv MIN
409and
410.Dv TIME
411and
412their interactions are described below.
413.Ss "Case A: MIN > 0, TIME > 0"
414In this case
415.Dv TIME
416serves as an inter-byte timer and is activated after
417the first byte is received.
418Since it is an inter-byte timer, it is reset
419after a byte is received.
420The interaction between
421.Dv MIN
422and
423.Dv TIME
424is as
425follows: as soon as one byte is received, the inter-byte timer is
426started.
427If
428.Dv MIN
429bytes are received before the inter-byte timer expires
430(remember that the timer is reset upon receipt of each byte), the read is
431satisfied.
432If the timer expires before
433.Dv MIN
434bytes are received, the
435characters received to that point are returned to the user.
436Note that if
437.Dv TIME
438expires at least one byte is returned because the timer would
439not have been enabled unless a byte was received.
440In this case
441.Pf \&( Dv MIN
442> 0,
443.Dv TIME
444> 0) the read blocks until the
445.Dv MIN
446and
447.Dv TIME
448mechanisms are
449activated by the receipt of the first byte, or a signal is received.
450If data is in the buffer at the time of the
451.Fn read ,
452the result is as
453if data had been received immediately after the
454.Fn read .
455.Ss "Case B: MIN > 0, TIME = 0"
456In this case, since the value of
457.Dv TIME
458is zero, the timer plays no role
459and only
460.Dv MIN
461is significant.
462A pending read is not satisfied until
463.Dv MIN
464bytes are received (i.e., the pending read blocks until
465.Dv MIN
466bytes
467are received), or a signal is received.
468A program that uses this case to read record-based terminal
469.Dv I/O
470may block indefinitely in the read
471operation.
472.Ss "Case C: MIN = 0, TIME > 0"
473In this case, since
474.Dv MIN
475= 0,
476.Dv TIME
477no longer represents an inter-byte
478timer.
479It now serves as a read timer that is activated as soon as the
480read function is processed.
481A read is satisfied as soon as a single
482byte is received or the read timer expires.
483Note that in this case if the timer expires, no bytes are returned.
484If the timer does not
485expire, the only way the read can be satisfied is if a byte is received.
486In this case the read will not block indefinitely waiting for a byte; if
487no byte is received within
488.Dv TIME Ns *0.1
489seconds after the read is initiated,
490the read returns a value of zero, having read no data.
491If data is
492in the buffer at the time of the read, the timer is started as if
493data had been received immediately after the read.
494.Ss Case D: MIN = 0, TIME = 0
495The minimum of either the number of bytes requested or the number of
496bytes currently available is returned without waiting for more
497bytes to be input.
498If no characters are available, read returns a
499value of zero, having read no data.
500.Ss Writing Data and Output Processing
501When a process writes one or more bytes to a terminal device file, they
502are processed according to the
503.Fa c_oflag
504field (see the
505.Sx "Output Modes"
506section).
507The
508implementation may provide a buffering mechanism; as such, when a call to
509.Fn write
510completes, all of the bytes written have been scheduled for
511transmission to the device, but the transmission will not necessarily
512have been completed.
513.\" See also .Sx "6.4.2" for the effects of
514.\" .Dv O_NONBLOCK
515.\" on write.
516.Ss Special Characters
517Certain characters have special functions on input or output or both.
518These functions are summarized as follows:
519.Bl -tag -width indent
520.It Dv INTR
521Special character on input and is recognized if the
522.Dv ISIG
523flag (see the
524.Sx "Local Modes"
525section) is enabled.
526Generates a
527.Dv SIGINT
528signal which is sent to all processes in the foreground
529process group for which the terminal is the controlling
530terminal.
531If
532.Dv ISIG
533is set, the
534.Dv INTR
535character is
536discarded when processed.
537.It Dv QUIT
538Special character on input and is recognized if the
539.Dv ISIG
540flag is enabled.
541Generates a
542.Dv SIGQUIT
543signal which is
544sent to all processes in the foreground process group
545for which the terminal is the controlling terminal.
546If
547.Dv ISIG
548is set, the
549.Dv QUIT
550character is discarded when
551processed.
552.It Dv ERASE
553Special character on input and is recognized if the
554.Dv ICANON
555flag is set.
556Erases the last character in the
557current line; see
558.Sx "Canonical Mode Input Processing" .
559It does not erase beyond
560the start of a line, as delimited by an
561.Dv NL ,
562.Dv EOF ,
563or
564.Dv EOL
565character.
566If
567.Dv ICANON
568is set, the
569.Dv ERASE
570character is
571discarded when processed.
572.It Dv KILL
573Special character on input and is recognized if the
574.Dv ICANON
575flag is set.
576Deletes the entire line, as
577delimited by a
578.Dv NL ,
579.Dv EOF ,
580or
581.Dv EOL
582character.
583If
584.Dv ICANON
585is set, the
586.Dv KILL
587character is discarded when processed.
588.It Dv EOF
589Special character on input and is recognized if the
590.Dv ICANON
591flag is set.
592When received, all the bytes
593waiting to be read are immediately passed to the
594process, without waiting for a newline, and the
595.Dv EOF
596is discarded.
597Thus, if there are no bytes waiting (that is, the
598.Dv EOF
599occurred at the beginning of a line), a byte
600count of zero is returned from the
601.Fn read ,
602representing an end-of-file indication.
603If
604.Dv ICANON
605is
606set, the
607.Dv EOF
608character is discarded when processed.
609.It Dv NL
610Special character on input and is recognized if the
611.Dv ICANON
612flag is set.
613It is the line delimiter
614.Ql \&\en .
615.It Dv EOL
616Special character on input and is recognized if the
617.Dv ICANON
618flag is set.
619Is an additional line delimiter, like
620.Dv NL .
621.It Dv SUSP
622If the
623.Dv ISIG
624flag is enabled, receipt of the
625.Dv SUSP
626character causes a
627.Dv SIGTSTP
628signal to be sent to all processes in the
629foreground process group for which the terminal is the
630controlling terminal, and the
631.Dv SUSP
632character is
633discarded when processed.
634.It Dv STOP
635Special character on both input and output and is
636recognized if the
637.Dv IXON
638(output control) or
639.Dv IXOFF
640(input
641control) flag is set.
642Can be used to temporarily suspend output.
643It is useful with fast terminals to
644prevent output from disappearing before it can be read.
645If
646.Dv IXON
647is set, the
648.Dv STOP
649character is discarded when
650processed.
651.It Dv START
652Special character on both input and output and is
653recognized if the
654.Dv IXON
655(output control) or
656.Dv IXOFF
657(input
658control) flag is set.
659Can be used to resume output that has been suspended by a
660.Dv STOP
661character.
662If
663.Dv IXON
664is set, the
665.Dv START
666character is discarded when processed.
667.It Dv CR
668Special character on input and is recognized if the
669.Dv ICANON
670flag is set; it is the
671.Ql \&\er ,
672as denoted in the
673.Tn \&C
674Standard {2}.
675When
676.Dv ICANON
677and
678.Dv ICRNL
679are set and
680.Dv IGNCR
681is not set, this character is translated into a
682.Dv NL ,
683and
684has the same effect as a
685.Dv NL
686character.
687.El
688.Pp
689The following special characters are extensions defined by this
690system and are not a part of
691.St -p1003.1
692termios.
693.Bl -tag -width indent
694.It Dv EOL2
695Secondary
696.Dv EOL
697character.
698Same function as
699.Dv EOL .
700.It Dv WERASE
701Special character on input and is recognized if the
702.Dv ICANON
703flag is set.
704Erases the last word in the current line according to one of two algorithms.
705If the
706.Dv ALTWERASE
707flag is not set, first any preceding whitespace is
708erased, and then the maximal sequence of non-whitespace
709characters.
710If
711.Dv ALTWERASE
712is set, first any preceding
713whitespace is erased, and then the maximal sequence
714of alphabetic/underscores or non alphabetic/underscores.
715As a special case in this second algorithm, the first previous
716non-whitespace character is skipped in determining
717whether the preceding word is a sequence of
718alphabetic/underscores.
719This sounds confusing but turns out to be quite practical.
720.It Dv REPRINT
721Special character on input and is recognized if the
722.Dv ICANON
723flag is set.
724Causes the current input edit line to be retyped.
725.It Dv DSUSP
726Has similar actions to the
727.Dv SUSP
728character, except that
729the
730.Dv SIGTSTP
731signal is delivered when one of the processes
732in the foreground process group issues a
733.Fn read
734to the
735controlling terminal.
736.It Dv LNEXT
737Special character on input and is recognized if the
738.Dv IEXTEN
739flag is set.
740Receipt of this character causes the next character to be taken literally.
741.It Dv DISCARD
742Special character on input and is recognized if the
743.Dv IEXTEN
744flag is set.
745Receipt of this character toggles the flushing of terminal output.
746.It Dv STATUS
747Special character on input and is recognized if the
748.Dv ICANON
749flag is set.
750Receipt of this character causes a
751.Dv SIGINFO
752signal to be sent to the foreground process group of the
753terminal.
754Also, if the
755.Dv NOKERNINFO
756flag is not set, it
757causes the kernel to write a status message to the terminal
758that displays the current load average, the name of the
759command in the foreground, its process ID, the symbolic
760wait channel, the number of user and system seconds used,
761the percentage of cpu the process is getting, and the resident
762set size of the process.
763.Pp
764In case the
765.Xr sysctl 8
766variable
767.Va kern.tty_info_kstacks
768is set to a non-zero value, the running thread's kernel stack is
769written to the terminal (e.g., for debugging purposes).
770.El
771.Pp
772The
773.Dv NL
774and
775.Dv CR
776characters cannot be changed.
777The values for all the remaining characters can be set and are
778described later in the document under
779Special Control Characters.
780.Pp
781Special
782character functions associated with changeable special control characters
783can be disabled individually by setting their value to
784.Dv {_POSIX_VDISABLE} ;
785see
786.Sx "Special Control Characters" .
787.Pp
788If two or more special characters have the same value, the function
789performed when that character is received is undefined.
790.Ss Modem Disconnect
791If a modem disconnect is detected by the terminal interface for a
792controlling terminal, and if
793.Dv CLOCAL
794is not set in the
795.Fa c_cflag
796field for
797the terminal, the
798.Dv SIGHUP
799signal is sent to the controlling
800process associated with the terminal.
801Unless other arrangements have
802been made, this causes the controlling process to terminate.
803Any subsequent call to the
804.Fn read
805function returns the value zero,
806indicating end of file.
807Thus, processes that read a terminal
808file and test for end-of-file can terminate appropriately after a
809disconnect.
810.\" If the
811.\" .Er EIO
812.\" condition specified in 6.1.1.4 that applies
813.\" when the implementation supports job control also exists, it is
814.\" unspecified whether the
815.\" .Dv EOF
816.\" condition or the
817.\" .Pf [ Dv EIO
818.\" ] is returned.
819Any
820subsequent
821.Fn write
822to the terminal device returns -1, with
823.Va errno
824set to
825.Er EIO ,
826until the device is closed.
827.Sh General Terminal Interface
828.Ss Closing a Terminal Device File
829The last process to close a terminal device file causes any output
830to be sent to the device and any input to be discarded.
831Then, if
832.Dv HUPCL
833is set in the control modes, and the communications port supports a
834disconnect function, the terminal device performs a disconnect.
835.Ss Parameters That Can Be Set
836Routines that need to control certain terminal
837.Tn I/O
838characteristics
839do so by using the termios structure as defined in the header
840.In termios.h .
841This structure contains minimally four scalar elements of bit flags
842and one array of special characters.
843The scalar flag elements are named:
844.Fa c_iflag ,
845.Fa c_oflag ,
846.Fa c_cflag ,
847and
848.Fa c_lflag .
849The character array is named
850.Fa c_cc ,
851and its maximum index is
852.Dv NCCS .
853.Ss Input Modes
854Values of the
855.Fa c_iflag
856field describe the basic
857terminal input control, and are composed of
858following masks:
859.Pp
860.Bl -tag -width IMAXBEL -offset indent -compact
861.It Dv IGNBRK
862/* ignore BREAK condition */
863.It Dv BRKINT
864/* map BREAK to SIGINTR */
865.It Dv IGNPAR
866/* ignore (discard) parity errors */
867.It Dv PARMRK
868/* mark parity and framing errors */
869.It Dv INPCK
870/* enable checking of parity errors */
871.It Dv ISTRIP
872/* strip 8th bit off chars */
873.It Dv INLCR
874/* map NL into CR */
875.It Dv IGNCR
876/* ignore CR */
877.It Dv ICRNL
878/* map CR to NL (ala CRMOD) */
879.It Dv IXON
880/* enable output flow control */
881.It Dv IXOFF
882/* enable input flow control */
883.It Dv IXANY
884/* any char will restart after stop */
885.It Dv IMAXBEL
886/* ring bell on input queue full */
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