xref: /illumos-gate/usr/src/man/man4i/termio.4i (revision 77c0a660417a046bfab6c8ef58d00c181c0264b3)
1.\" Copyright (c) 2005, Sun Microsystems, Inc.  All Rights Reserved.
2.\" Copyright 2019, Joyent, Inc.  All Rights Reserved.
3.\" Copyright 1989 AT&T
4.\" The contents of this file are subject to the terms of the
5.\" Common Development and Distribution License (the "License").
6.\" You may not use this file except in compliance with the License.
7.\"
8.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9.\" or http://www.opensolaris.org/os/licensing.
10.\" See the License for the specific language governing permissions
11.\" and limitations under the License.
12.\"
13.\" When distributing Covered Code, include this CDDL HEADER in each
14.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15.\" If applicable, add the following below this CDDL HEADER, with the
16.\" fields enclosed by brackets "[]" replaced with your own identifying
17.\" information: Portions Copyright [yyyy] [name of copyright owner]
18.Dd March 13, 2022
19.Dt TERMIO 4I
20.Os
21.Sh NAME
22.Nm termio
23.Nd general terminal interface
24.Sh SYNOPSIS
25.In termio.h
26.Fn ioctl "int fildes" "int request" "struct termio *arg"
27.Fn ioctl "int fildes" "int request" "int arg"
28.Pp
29.In termios.h
30.Fn ioctl "int fildes" "int request" "struct termios *arg"
31.Sh DESCRIPTION
32This release supports a general interface for asynchronous communications ports
33that is hardware-independent.
34The user interface to this functionality is using
35function calls (the preferred interface) described in
36.Xr termios 3C
37or
38.Fn ioctl
39commands described in this section.
40This section also discusses the
41common features of the terminal subsystem which are relevant with both user
42interfaces.
43.Pp
44When a terminal file is opened, it normally causes the process to wait until a
45connection is established.
46In practice, user programs seldom open terminal
47files; they are opened by the system and become a user's standard input,
48output, and error files.
49The first terminal file opened by the session leader
50that is not already associated with a session becomes the controlling terminal
51for that session.
52The controlling terminal plays a special role in handling
53quit and interrupt signals, as discussed below.
54The controlling terminal is
55inherited by a child process during a
56.Xr fork 2 .
57A process can break this
58association by changing its session using
59.Xr setsid 2 .
60.Pp
61A terminal associated with one of these files ordinarily operates in
62full-duplex mode.
63Characters may be typed at any time, even while output is
64occurring, and are only lost when the character input buffers of the system
65become completely full, which is rare.
66For example, the number of characters in
67the line discipline buffer may exceed
68.Brq Dv MAX_CANON
69and
70.Dv IMAXBEL
71(see below) is not set, or the user may accumulate
72.Brq Dv MAX_INPUT
73number of input characters that have not yet been read by some program.
74When the input
75limit is reached, all the characters saved in the buffer up to that point are
76thrown away without notice.
77.Ss "Session Management (Job Control)"
78A control terminal will distinguish one of the process groups in the session
79associated with it to be the foreground process group.
80All other process
81groups in the session are designated as background process groups.
82This foreground process group plays a special role in handling signal-generating
83input characters, as discussed below.
84By default, when a controlling terminal
85is allocated, the controlling process's process group is assigned as
86foreground process group.
87.Pp
88Background process groups in the controlling process's session are subject to a
89job control line discipline when they attempt to access their controlling
90terminal.
91Process groups can be sent signals that will cause them to stop,
92unless they have made other arrangements.
93An exception is made for members of
94orphaned process groups.
95.Pp
96An orphaned process group is one where the process group (see
97.Xr getpgid 2 )
98has no members with a parent in a different process group but sharing the same
99controlling terminal.
100When a member of an orphaned process group attempts to
101access its controlling terminal, EIO is returned because there would be no way
102to restart the process if it were stopped on one of these signals.
103.Pp
104If a member of a background process group attempts to read its controlling
105terminal, its process group will be sent a
106.Dv SIGTTIN
107signal, which will
108normally cause the members of that process group to stop.
109If, however, the
110process is ignoring or holding
111.Dv SIGTTIN ,
112or is a member of an orphaned
113process group, the read will fail with
114.Va errno
115set to
116.Er EIO ,
117and no signal is sent.
118.Pp
119If a member of a background process group attempts to write its controlling
120terminal and the
121.Dv TOSTOP
122bit is set in the
123.Fa c_lflag
124field, its process group is sent a
125.Dv SIGTTOU
126signal, which will normally cause the
127members of that process group to stop.
128If, however, the process is ignoring or
129holding
130.Dv SIGTTOU ,
131the write will succeed.
132If the process is not ignoring
133or holding
134.Dv SIGTTOU
135and is a member of an orphaned process group, the
136write will fail with
137.Va errno
138set to
139.Er EIO ,
140and no signal will be sent.
141.Pp
142If
143.Dv TOSTOP
144is set and a member of a background process group attempts to
145.Fn ioctl
146its controlling terminal, and that
147.Fn ioctl
148will modify terminal parameters (for example,
149.Dv TCSETA ,
150.Dv TCSETAW ,
151.Dv TCSETAF ,
152or
153.Dv TIOCSPGRP ) ,
154its process group will be sent a
155.Dv SIGTTOU
156signal, which will normally cause the members of that process group to stop.
157If, however, the process is ignoring or holding
158.Dv SIGTTOU ,
159the ioctl will succeed.
160If the process is not ignoring or holding
161.Dv SIGTTOU
162and is a member of an orphaned
163process group, the write will fail with
164.Va errno
165set to
166.Er EIO ,
167and no signal will be sent.
168.Ss "Canonical Mode Input Processing"
169Normally, terminal input is processed in units of lines.
170A line is delimited by
171a newline
172.Po
173.Sy ASCII LF
174.Pc
175character, an end-of-file
176.Po
177.Sy ASCII EOT
178.Pc
179character, or an end-of-line character.
180This means that a program attempting to
181read will block until an entire line has been typed.
182Also, no matter how many
183characters are requested in the read call, at most one line will be returned.
184It is not necessary, however, to read a whole line at once; any number of
185characters may be requested in a read, even one, without losing information.
186.Pp
187During input, erase, erase2, and kill processing is normally done.
188The
189.Sy ERASE
190and
191.Sy ERASE2
192character (by default, the character
193.Sy DEL
194for
195.Sy ERASE
196and
197.Sy Control-h
198for
199.Sy ERASE2 )
200erases the last character typed.
201The
202.Sy WERASE
203character (the character
204.Sy Control-w )
205erases the
206last "word" typed in the current input line (but not any preceding spaces or
207tabs).
208A
209.Dq word
210is defined as a sequence of non-blank characters, with tabs counted as blanks.
211None of
212.Sy ERASE
213or
214.Sy ERASE2
215or
216.Sy WERASE
217will erase beyond the beginning of the line.
218The
219.Sy KILL
220character (by default,
221the character
222.Sy NAK )
223kills (deletes) the entire input line, and optionally
224outputs a newline character.
225All these characters operate on a key stroke basis,
226independent of any backspacing or tabbing that may have been done.
227The
228.Sy REPRINT
229character (the character
230.Sy Control-r )
231prints a newline followed by all characters that have not been read.
232Reprinting also occurs automatically if
233characters that would normally be erased from the screen are fouled by program
234output.
235The characters are reprinted as if they were being echoed;
236consequently, if
237.Dv ECHO
238is not set, they are not printed.
239.Pp
240The
241.Sy ERASE ,
242.Sy ERASE2 ,
243and
244.Sy KILL
245characters may be entered literally by preceding them with the escape character.
246In this case, the escape character is not read.
247The erase, erase2, and kill characters may be changed.
248.Ss "Non-canonical Mode Input Processing"
249In non-canonical mode input processing, input characters are not assembled into
250lines, and erase and kill processing does not occur.
251The
252.Sy MIN
253and
254.Sy TIME
255values are used to determine how to process the characters received.
256.Pp
257.Sy MIN
258represents the minimum number of characters that should be received
259when the read is satisfied (that is, when the characters are returned to the
260user).
261.Sy TIME
262is a timer of 0\&.10-second granularity that is used to timeout
263bursty and short-term data transmissions.
264The four possible values for
265.Sy MIN
266and
267.Sy TIME
268and their interactions are described below.
269.Bl -tag -width "Case A: Min > 0, Time > 0"
270.It Sy Case A: MIN > 0, TIME > 0
271In this case,
272.Sy TIME
273serves as an intercharacter timer and is activated
274after the first character is received.
275Since it is an intercharacter timer, it
276is reset after a character is received.
277The interaction between
278.Sy MIN
279and
280.Sy TIME
281is as follows: as soon as one character is received, the
282intercharacter timer is started.
283If
284.Sy MIN
285characters are received before
286the intercharacter timer expires (note that the timer is reset upon receipt of
287each character), the read is satisfied.
288If the timer expires before
289.Sy MIN
290characters are received, the characters received to that point are returned to
291the user.
292Note that if
293.Sy TIME
294expires, at least one character will be
295returned because the timer would not have been enabled unless a character was
296received.
297In this case (MIN > 0, TIME > 0), the read sleeps until the
298.Sy MIN
299and
300.Sy TIME
301mechanisms are activated by the receipt of the first character.
302If the number of characters read is less than the number of characters
303available, the timer is not reactivated and the subsequent read is satisfied
304immediately.
305.It Sy Case B: MIN > 0, TIME = 0
306In this case, since the value of
307.Sy TIME
308is zero, the timer plays no role
309and only
310.Sy MIN
311is significant.
312A pending read is not satisfied until
313.Sy MIN
314characters are received (the pending read sleeps until
315.Sy MIN
316characters are received).
317A program that uses this case to read record based
318terminal
319.Sy I/O
320may block indefinitely in the read operation.
321.It Sy Case C: MIN = 0, TIME > 0
322In this case, since
323.Sy MIN
3240,
325.Sy TIME
326no longer represents an
327intercharacter timer: it now serves as a read timer that is activated as soon
328as a
329.Xr read  2
330is done.
331A read is satisfied as soon as a single character is
332received or the read timer expires.
333Note that, in this case, if the timer
334expires, no character is returned.
335If the timer does not expire, the only way
336the read can be satisfied is if a character is received.
337In this case, the
338read will not block indefinitely waiting for a character; if no character is
339received within
340.Sy TIME
341*\&.10 seconds after the read is initiated, the read
342returns with zero characters.
343.It Sy Case D: MIN = 0, TIME = 0
344In this case, return is immediate.
345The minimum of either the number of
346characters requested or the number of characters currently available is
347returned without waiting for more characters to be input.
348.El
349.Ss "Comparing Different Cases of MIN, TIME Interaction"
350Some points to note about
351.Sy MIN
352and
353.Sy TIME :
354.Bl -bullet -offset 2n
355.It
356In the following explanations, note that the interactions of
357.Sy MIN
358and
359.Sy TIME
360are not symmetric.
361For example, when
362.Sy MIN
363> 0 and
364.Sy TIME
365= 0,
366.Sy TIME
367has no effect.
368However, in the opposite case, where
369.Sy MIN
370= 0 and
371.Sy TIME
372> 0, both
373.Sy MIN
374and
375.Sy TIME
376play a role in that
377.Sy MIN
378is satisfied with the receipt of a single character.
379.It
380Also note that in case A
381.Po
382.Sy MIN
383> 0,
384.Sy TIME
385> 0
386.Pc ,
387.Sy TIME
388represents
389an intercharacter timer, whereas in case C
390.Po
391.Sy MIN
392= 0,
393.Sy TIME
394> 0
395.Pc ,
396.Sy TIME
397represents a read timer.
398.El
399.Pp
400These two points highlight the dual purpose of the
401.Sy MIN/TIME
402feature.
403Cases A and B, where
404.Sy MIN
405> 0, exist to handle burst mode activity (for
406example, file transfer programs), where a program would like to process at
407least
408.Sy MIN
409characters at a time.
410In case A, the intercharacter timer is
411activated by a user as a safety measure; in case B, the timer is turned off.
412.Pp
413Cases C and D exist to handle single character, timed transfers.
414These cases
415are readily adaptable to screen-based applications that need to know if a
416character is present in the input queue before refreshing the screen.
417In case
418C, the read is timed, whereas in case D, it is not.
419.Pp
420Another important note is that
421.Sy MIN
422is always just a minimum.
423It does not
424denote a record length.
425For example, if a program does a read of 20 bytes,
426.Sy MIN
427is 10, and 25 characters are present, then 20 characters will be
428returned to the user.
429.Ss "Writing Characters"
430When one or more characters are written, they are transmitted to the terminal
431as soon as previously written characters have finished typing.
432nputt characters
433are echoed as they are typed if echoing has been enabled.
434If a process produces
435characters more rapidly than they can be typed, it will be suspended when its
436output queue exceeds some limit.
437When the queue is drained down to some
438threshold, the program is resumed.
439.Ss "Special Characters"
440Certain characters have special functions on input.
441These functions and their default character values are summarized as follows:
442.Bl -tag -width REPRINT
443.It Sy INTR
444(Control-c or
445.Sy ASCII ETX )
446generates a
447.Dv SIGINT
448signal.
449.Dv SIGINT
450is sent to all foreground processes associated with the controlling terminal.
451Normally, each such process is forced to terminate, but arrangements may be
452made either to ignore the signal or to receive a trap to an agreed upon
453location.
454(See
455.Xr signal.h 3HEAD ) .
456.It Sy QUIT
457(Control-| or
458.Sy ASCII FS )
459generates a
460.Dv SIGQUIT
461signal.
462Its treatment
463is identical to the interrupt signal except that, unless a receiving process
464has made other arrangements, it will not only be terminated but a core image
465file (called
466.Pa core )
467will be created in the current working directory.
468.It Sy ERASE
469(DEL) erases the preceding character.
470It does not erase beyond
471the start of a line, as delimited by a
472.Sy NL ,
473.Sy EOF ,
474.Sy EOL ,
475or
476.Sy EOL2
477character.
478.It Sy ERASE2
479(Control-h or
480.Sy ASCII BS )
481erases the preceding character, with behaviour identical to that of ERASE.
482.It Sy WERASE
483(Control-w or
484.Sy ASCII ETX )
485erases the preceding
486.Dq word .
487It does not erase beyond the start of a line, as delimited by a
488.Sy NL ,
489.Sy EOF ,
490.Sy EOL ,
491or
492.Sy EOL2
493character.
494.It Sy KILL
495(Control-u or
496.Sy ASCII NAK )
497deletes the entire line, as delimited by a
498.Sy NL ,
499.Sy EOF ,
500.Sy EOL ,
501or
502.Sy EOL2
503character.
504.It Sy REPRINT
505(Control-r or
506.Sy ASCII DC2 )
507reprints all characters, preceded by a newline, that have not been read.
508.It Sy EOF
509(Control-d or
510.Sy ASCII EOT )
511may be used to generate an end-of-file from a terminal.
512When received, all the characters waiting to be read are immediately
513passed to the program, without waiting for a newline, and the
514.Sy EOF
515is discarded.
516Thus, if no characters are waiting (that is, the
517.Sy EOF
518occurred
519at the beginning of a line) zero characters are passed back, which is the
520standard end-of-file indication.
521Unless escaped, the
522.Sy EOF
523character is not
524echoed.
525Because
526.Sy EOT
527is the default
528.Sy EOF
529character, this prevents
530terminals that respond to
531.Sy EOT
532from hanging up.
533.It Sy NL
534.Pq Sy ASCII LF
535is the normal line delimiter.
536It cannot be changed or escaped.
537.It Sy EOL
538.Pq Sy ASCII NULL
539is an additional line delimiter, like
540.Sy NL .
541It is not normally used.
542.It Sy EOL2
543is another additional line delimiter.
544.It Sy SWTCH
545(Control-z or
546.Sy ASCII EM )
547Header file symbols related to this special
548character are present for compatibility purposes only and the kernel takes no
549special action on matching SWTCH (except to discard the character).
550.It Sy SUSP
551(Control-z or
552.Sy ASCII SUB )
553generates a
554.Dv SIGTSTP
555signal.
556.Dv SIGTSTP
557stops all processes in the foreground process group for that terminal.
558.It Sy DSUSP
559(Control-y or
560.Sy ASCII EM ) .
561It generates a
562.Dv SIGTSTP
563signal as
564.Sy SUSP
565does, but the signal is sent when a process in the foreground
566process group attempts to read the
567.Sy DSUSP
568character, rather than when it is typed.
569.It Sy STOP
570(Control-s or
571.Sy ASCII DC3 )
572can be used to suspend output temporarily.
573It is useful with
574.Sy CRT
575terminals to prevent output from disappearing before it can be read.
576While output is suspended,
577.Sy STOP
578characters are ignored and
579not read.
580.It Sy START
581(Control-q or
582.Sy ASCII DC1 )
583is used to resume output.
584Output has been suspended by a
585.Sy STOP
586character.
587While output is not suspended,
588.Sy START
589characters are ignored and not read.
590.It Sy DISCARD
591(Control-o or
592.Sy ASCII SI )
593causes subsequent output to be discarded.
594Output is discarded until another
595.Sy DISCARD
596character is typed, more input
597arrives, or the condition is cleared by a program.
598.It Sy STATUS
599(Control-t or
600.Sy ASCII DC4 )
601generates a
602.Dv SIGINFO
603signal.
604Processes with a handler will output status information when they receive
605.Dv SIGINFO ,
606for
607example,
608.Xr dd 8 .
609If a process does not have a
610.Dv SIGINFO
611handler, the
612signal will be ignored.
613.It Sy LNEXT
614(Control-v or
615.Sy ASCII SYN )
616causes the special meaning of the next character to be ignored.
617This works for all the special characters mentioned above.
618It
619allows characters to be input that would otherwise be interpreted by the system
620(for example
621.Sy KILL ,
622.Sy QUIT ) .
623The character values for
624.Sy INTR ,
625.Sy QUIT ,
626.Sy ERASE ,
627.Sy ERASE2 ,
628.Sy WERASE ,
629.Sy KILL ,
630.Sy REPRINT ,
631.Sy EOF ,
632.Sy EOL ,
633.Sy EOL2 ,
634.Sy SWTCH ,
635.Sy SUSP ,
636.Sy DSUSP ,
637.Sy STOP ,
638.Sy START ,
639.Sy DISCARD ,
640.Sy STATUS ,
641and
642.Sy LNEXT
643may be changed to suit individual tastes.
644If the value of a special control character
645is
646.Dv _POSIX_VDISABLE
647(0), the function of that special control character is disabled.
648The
649.Sy ERASE ,
650.Sy ERASE2 ,
651.Sy KILL ,
652and
653.Sy EOF
654characters may be
655escaped by a preceding backslash (\e) character, in which case no special
656function is done.
657Any of the special characters may be preceded by the
658.Sy LNEXT
659character, in
660which case no special function is done.
661.El
662.Ss "Modem Disconnect"
663When a modem disconnect is detected, a
664.Dv SIGHUP
665signal is sent to the
666terminal's controlling process.
667Unless other arrangements have been made, these
668signals cause the process to terminate.
669If
670.Dv SIGHUP
671is ignored or caught,
672any subsequent read returns with an end-of-file indication until the terminal
673is closed.
674.Pp
675If the controlling process is not in the foreground process group of the
676terminal, a
677.Dv SIGTSTP
678is sent to the terminal's foreground process group.
679Unless other arrangements have been made, these signals cause the processes to
680stop.
681.Pp
682Processes in background process groups that attempt to access the controlling
683terminal after modem disconnect while the terminal is still allocated to the
684session will receive appropriate
685.Dv SIGTTOU
686and
687.Dv SIGTTIN
688signals.
689Unless other arrangements have been made, this signal causes the processes to
690stop.
691.Pp
692The controlling terminal will remain in this state until it is reinitialized
693ithh a successful open by the controlling process, or deallocated by the
694controlling process.
695.Ss "Terminal Parameters"
696The parameters that control the behavior of devices and modules providing the
697.Vt termios
698interface are specified by the
699.Vt termios
700structure defined by
701.In termios.h .
702Several
703.Xr ioctl 2
704system calls that fetch or change
705these parameters use this structure that contains the following members:
706.Bd -literal -offset 2n
707tcflag_t	c_iflag;	/* input modes */
708tcflag_t	c_oflag;	/* output modes */
709tcflag_t	c_cflag;	/* control modes */
710tcflag_t	c_lflag;	/* local modes */
711cc_t		c_cc[NCCS];	/* control chars */
712.Ed
713.Pp
714The special control characters are defined by the array
715.Fa c_cc .
716The symbolic name
717.Dv NCCS
718is the size of the Control-character array and is also
719defined by
720.In termios.h .
721The relative positions, subscript names, and
722typical default values for each function are as follows:
723.Bl -column "Relative Position" "Subscript Name" "Typical Default Value"
724.It Relative Position Ta Subscript Name Ta Typical Default Value
725.It 0 Ta Dv VINTR Ta Sy ETX
726.It 1 Ta Dv VQUIT Ta Sy FS
727.It 2 Ta Dv VERASE Ta Sy DEL
728.It 3 Ta Dv VKILL Ta Sy NAK
729.It 4 Ta Dv VEOF Ta Sy EOT
730.It 5 Ta Dv VEOL Ta Sy NUL
731.It 6 Ta Dv VEOL2 Ta Sy NUL
732.It 7 Ta Dv VWSTCH Ta Sy NUL
733.It 8 Ta Dv VSTART Ta Sy NUL
734.It 9 Ta Dv VSTOP Ta Sy DC3
735.It 10 Ta Dv VSUSP Ta Sy SUB
736.It 11 Ta Dv VDSUSP Ta Sy EM
737.It 12 Ta Dv VREPRINT Ta Sy DC2
738.It 13 Ta Dv VDISCARD Ta Sy SI
739.It 14 Ta Dv VWERASE Ta Sy ETB
740.It 15 Ta Dv VLNEXT Ta Sy SYN
741.It 16 Ta Dv VSTATUS Ta Sy DC4
742.It 17 Ta Dv VERASE2 Ta Sy BS
743.It 18-19 Ta Reserved Ta
744.El
745.Ss "Input Modes"
746The
747.Fa c_iflag
748field describes the basic terminal input control:
749.Pp
750.Bl -tag -width "IMAXBEL" -offset 2n -compact
751.It Dv IGNBRK
752Ignore break condition.
753.It Dv BRKINT
754Signal interrupt on break.
755.It Dv IGNPAR
756Ignore characters with parity errors.
757.It Dv PARMRK
758Mark parity errors.
759.It Dv INPCK
760Enable input parity check.
761.It Dv ISTRIP
762Strip character.
763.It Dv INLCR
764Map NL to CR on input.
765.It Dv IGNCR
766Ignore CR.
767.It Dv ICRNL
768Map CR to NL on input.
769.It Dv IUCLC
770Map upper-case to lower-case on input.
771.It Dv IXON
772Enable start/stop output control.
773.It Dv IXANY
774Enable any character to restart output.
775.It Dv IXOFF
776Enable start/stop input control.
777.It Dv IMAXBEL
778Echo
779.Sy BEL
780on input line too long.
781.El
782.Pp
783If
784.Dv IGNBRK
785is set, a break condition (a character framing error with data
786all zeros) detected on input is ignored, that is, not put on the input queue
787and therefore not read by any process.
788If
789.Dv IGNBRK
790is not set and
791.Dv BRKINT
792is set, the break condition shall flush the input and output
793queues and if the terminal is the controlling terminal of a foreground process
794group, the break condition generates a single
795.Dv SIGINT
796signal to that
797foreground process group.
798If neither
799.Dv IGNBRK
800nor
801.Dv BRKINT
802is set, a
803break condition is read as a single
804.Ql \e0
805.Pq Sy ASCII NULL
806character, or if
807.Dv PARMRK
808is set, as
809.Ql \e377 ,
810.Ql \e0 ,
811.Em c ,
812where
813.Ql \e377
814is a single character
815with value 377 octal (0xff hex, 255 decimal),
816.Ql \e0
817is a single character with value
818.Sy 0 ,
819and
820.Em c
821is the errored character received.
822.Pp
823If
824.Dv IGNPAR
825is set, a byte with framing or parity errors (other than
826break) is ignored.
827.Pp
828If
829.Dv PARMRK
830is set, and
831.Dv IGNPAR
832is not set, a byte with a framing or
833parity error (other than break) is given to the application as the
834three-character sequence:
835.Ql \e377 ,
836.Ql \e0 ,
837c, where
838.Ql \e377
839is a single character with value 377 octal (0xff hex, 255 decimal),
840.Ql \e0
841is a single character with value 0, and c is the errored character received.
842To avoid ambiguity in this case, if
843.Dv ISTRIP
844is not set, a valid character
845of
846.Ql \e377
847is given to the application as
848.Ql \e377 .
849If neither
850.Dv IGNPAR
851nor
852.Dv PARMRK
853is set, a framing or parity error (other than break) is given to
854the application as a single
855.Ql \e0
856.Po
857.Sy ASCII NULL
858.Pc
859character.
860.Pp
861If
862.Dv INPCK
863is set, input parity checking is enabled.
864If
865.Dv INPCK
866is not
867set, input parity checking is disabled.
868This allows output parity generation
869without input parity errors.
870Note that whether input parity checking is
871enabled or disabled is independent of whether parity detection is enabled or
872disabled.
873If parity detection is enabled but input parity checking is
874disabled, the hardware to which the terminal is connected will recognize the
875parity bit, but the terminal special file will not check whether this is set
876correctly or not.
877.Pp
878If
879.Dv ISTRIP
880is set, valid input characters are first stripped to seven
881bits, otherwise all eight bits are processed.
882.Pp
883If
884.Dv INLCR
885is set, a received
886.Sy NL
887character is translated into a
888.Sy CR
889character.
890If
891.Dv IGNCR
892is set, a received
893.Sy CR
894character is ignored (not read).
895Otherwise, if
896.Dv ICRNL
897is set, a received
898.Sy CR
899character is translated into a
900.Sy NL
901character.
902.Pp
903If
904.Dv IUCLC
905is set, a received upper case, alphabetic character is
906translated into the corresponding lower case character.
907.Pp
908If
909.Dv IXON
910is set, start/stop output control is enabled.
911A received
912.Sy STOP
913character suspends output and a received
914.Sy START
915character
916restarts output.
917The
918.Sy STOP
919and
920.Sy START
921characters will not be read,
922but will merely perform flow control functions.
923If
924.Dv IXANY
925is set, any
926input character restarts output that has been suspended.
927.Pp
928If
929.Dv IXOFF
930is set, the system transmits a
931.Sy STOP
932character when the
933input queue is nearly full, and a
934.Sy START
935character when enough input has
936been read so that the input queue is nearly empty again.
937.Pp
938If
939.Dv IMAXBEL
940is set, the
941.Sy ASCII BEL
942character is echoed if the input stream overflows.
943Further input is not stored, but any input already present in
944the input stream is not disturbed.
945If
946.Dv IMAXBEL
947is not set, no
948.Sy BEL
949character is echoed, and all input present in the input queue is discarded if
950the input stream overflows.
951.Ss "Output Modes"
952The
953.Fa c_oflag
954field specifies the system treatment of output:
955.Pp
956.Bl -tag -width ONLRET -offset 2n -compact
957.It Dv OPOST
958Post-process output.
959.It Dv OLCUC
960Map lower case to upper on output.
961.It Dv ONLCR
962Map NL to CR-NL on output.
963.It Dv OCRNL
964Map CR to NL on output.
965.It Dv ONOCR
966No
967.Sy CR
968output at column 0.
969.It Dv ONLRET
970.Sy NL
971performs
972.Sy CR
973function.
974.It Dv OFILL
975Use fill characters for delay.
976.It Dv OFDEL
977Fill is
978.Sy DEL ,
979else
980.Sy INULL .
981.It Dv NLDLY
982Select newline delays:
983.Bl -tag -width NL0 -compact -offset 2n
984.It Sy NL0
985.It Sy NL1
986.El
987.It Dv CRDLY
988Select carriage-return delays:
989.Bl -tag -width CR0 -compact -offset 2n
990.It Dv CR0
991.It Dv CR1
992.It Dv CR2
993.It Dv CR3
994.El
995.It Dv TABDLY
996Select horizontal tab delays or tab expansion:
997.Bl -tag -width XTABS -compact -offset 2n
998.It Dv TAB0
999.It Dv TAB1
1000.It Dv TAB2
1001.It Dv TAB3
1002Expand tabs to spaces
1003.It Dv XTABS
1004Expand tabs to spaces
1005.El
1006.It Dv BSDLY
1007Select backspace delays:
1008.Bl -tag -width BS0 -offset 2n -compact
1009.It Dv BS0
1010.It Dv BS1
1011.El
1012.It Dv VTDLY
1013Select vertical tab delays:
1014.Bl -tag -width VT0 -offset 2n -compact
1015.It Dv VT0
1016.It Dv VT1
1017.El
1018.It Dv FFDLY
1019Select form feed delays:
1020.Bl -tag -width FF0 -offset 2n -compact
1021.It Dv FF0
1022.It Dv FF1
1023.El
1024.El
1025.Pp
1026If
1027.Dv OPOST
1028is set, output characters are post-processed as indicated by the
1029remaining flags; otherwise, characters are transmitted without change.
1030.Pp
1031If
1032.Dv OLCUC
1033is set, a lower case alphabetic character is transmitted as the
1034corresponding upper case character.
1035This function is often used in conjunction
1036with
1037.Dv IUCLC .
1038.Pp
1039If
1040.Dv ONLCR
1041is set, the
1042.Sy NL
1043character is transmitted as the
1044.Sy CR-NL
1045character pair.
1046If
1047.Dv OCRNL
1048is set, the
1049.Sy CR
1050character is transmitted as the
1051.Sy NL
1052character.
1053If
1054.Dv ONOCR
1055is set, no
1056.Sy CR
1057character is transmitted when at column 0 (first position).
1058If
1059.Dv ONRET
1060is set, the
1061.Sy NL
1062character is assumed to do the carriage-return function; the column
1063pointer is set to 0 and the delays specified for
1064.Sy CR
1065are used.
1066Otherwise, the
1067.Sy NL
1068character is assumed to do just the line-feed function; the column
1069pointer remains unchanged.
1070The column pointer is also set to 0 if the
1071.Sy CR
1072character is actually transmitted.
1073.Pp
1074The delay bits specify how long transmission stops to allow for mechanical or
1075other movement when certain characters are sent to the terminal.
1076In all cases, a value of 0 indicates no delay.
1077If
1078.Dv OFILL
1079is set, fill characters are transmitted for delay instead of a timed delay.
1080This is useful for high baud rate terminals that need only a minimal delay.
1081If
1082.Dv OFDEL
1083is set, the
1084fill character is
1085.Sy DEL ;
1086otherwise it is
1087.Sy NULL .
1088.Pp
1089If a form-feed or vertical-tab delay is specified, it lasts for about 2
1090seconds.
1091.Pp
1092Newline delay lasts about 0\&.10 seconds.
1093If
1094.Dv ONLRET
1095is set, the carriage-return delays are used instead of the newline delays.
1096If
1097.Dv OFILL
1098is set, two fill characters are transmitted.
1099.Pp
1100Carriage-return delay type 1 is dependent on the current column position, type
11012 is about 0\&.10 seconds, and type 3 is about 0\&.15 seconds.
1102If
1103.Dv OFILL
1104is set, delay type 1 transmits two fill characters, and type 2 transmits four
1105fill characters.
1106.Pp
1107Horizontal-tab delay type 1 is dependent on the current column position.
1108Type 2 is about 0\&.10 seconds.
1109Type 3 specifies that tabs are to be expanded into spaces.
1110If
1111.Dv OFILL
1112is set, two fill characters are transmitted for any delay.
1113.Pp
1114Backspace delay lasts about 0\&.05 seconds.
1115If
1116.Dv OFILL
1117is set, one fill character is transmitted.
1118.Pp
1119The actual delays depend on line speed and system load.
1120.Ss "Control Modes"
1121The
1122.Fa c_cflag
1123field describes the hardware control of the terminal:
1124.Bl -tag -width CIBAUDEXT -offset 2n
1125.It Dv CBAUD
1126Baud rate:
1127.Bl -tag -width B4000000 -compact
1128.It Dv B0
1129Hang up
1130.It Dv B50
113150 baud
1132.It Dv B75
113375 baud
1134.It Dv B110
1135110 baud
1136.It Dv B134
1137134 baud
1138.It Dv B150
1139150 baud
1140.It Dv B200
1141200 baud
1142.It Dv B300
1143300 baud
1144.It Dv B600
1145600 baud
1146.It Dv B1200
11471200 baud
1148.It Dv B1800
11491800 baud
1150.It Dv B2400
11512400 baud
1152.It Dv B4800
11534800 baud
1154.It Dv B9600
11559600 baud
1156.It Dv B19200
115719200 baud
1158.It Dv B38400
115938400 baud
1160.It Dv B57600
116157600 baud
1162.It Dv B76800
116376800 baud
1164.It Dv B115200
1165115200 baud
1166.It Dv B153600
1167153600 baud
1168.It Dv B230400
1169230400 baud
1170.It Dv B307200
1171307200 baud
1172.It Dv B460800
1173460800 baud
1174.It Dv B921600
1175921600 baud
1176.It Dv B1000000
11771000000 baud
1178.It Dv B1152000
11791152000 baud
1180.It Dv B1500000
11811500000 baud
1182.It Dv B2000000
11832000000 baud
1184.It Dv B2500000
11852500000 baud
1186.It Dv B3000000
11873000000 baud
1188.It Dv B3500000
11893500000 baud
1190.It Dv B4000000
11914000000 baud
1192.El
1193.It Dv CSIZE
1194Character size:
1195.Bl -tag -width CIBAUDEXT -compact
1196.It Dv CS5
11975 bits
1198.It Dv CS6
11996 bits
1200.It Dv CS7
12017 bits
1202.It Dv CS8
12038 bits
1204.It Dv CSTOPB
1205Send two stop bits, else one
1206.It Dv CREAD
1207Enable receiver
1208.It Dv PARENB
1209Parity enable
1210.It Dv PARODD
1211Odd parity, else even
1212.It Dv HUPCL
1213Hang up on last close
1214.It Dv CLOCAL
1215Local line, else dial-up
1216.It Dv CIBAUD
1217Input baud rate, if different from output rate
1218.It Dv PAREXT
1219Extended parity for mark and space parity
1220.It Dv CRTSXOFF
1221Enable inbound hardware flow control
1222.It Dv CRTSCTS
1223Enable outbound hardware flow control
1224.It Dv CBAUDEXT
1225Bit to indicate output speed > B38400
1226.It Dv CIBAUDEXT
1227Bit to indicate input speed > B38400
1228.El
1229.El
1230.Pp
1231The
1232.Dv CBAUD
1233bits together with the
1234.Dv CBAUDEXT
1235bit specify the output baud rate.
1236To retrieve the output speed from the
1237.Vt termios
1238structure pointed to by
1239.Fa termios_p
1240see the following code segment.
1241.Bd -literal -offset 2n
1242speed_t ospeed;
1243if (termios_p->c_cflag & CBAUDEXT)
1244 ospeed = (termios_p->c_cflag & CBAUD) + CBAUD + 1;
1245else
1246 ospeed = termios_p->c_cflag & CBAUD;
1247.Ed
1248.Pp
1249To store the output speed in the termios structure pointed to by
1250.Fa termios_p
1251see the following code segment.
1252.Bd -literal -offset 2n
1253speed_t ospeed;
1254if (ospeed > CBAUD) {
1255 termios_p->c_cflag |= CBAUDEXT;
1256 ospeed -= (CBAUD + 1);
1257} else {
1258 termios_p->c_cflag &= ~CBAUDEXT;
1259}
1260termios_p->c_cflag =
1261  (termios_p->c_cflag & ~CBAUD) | (ospeed & CBAUD);
1262.Ed
1263.Pp
1264The zero baud rate,
1265.Dv B0 ,
1266is used to hang up the connection.
1267If
1268.Dv B0
1269is specified, the data-terminal-ready signal is not asserted.
1270Normally, this disconnects the line.
1271.Pp
1272If the
1273.Dv CIBAUDEXT
1274or
1275.Dv CIBAUD
1276bits are not zero, they specify the input baud rate, with the
1277.Dv CBAUDEXT
1278and
1279.Dv CBAUD
1280bits specifying the output baud rate; otherwise, the output and input baud
1281rates are both specified by the
1282.Dv CBAUDEXT
1283and
1284.Dv CBAUD
1285bits.
1286The values for the
1287.Dv CIBAUD
1288bits are the same as the values for the
1289.Dv CBAUD
1290bits, shifted left
1291.Dv IBSHIFT
1292bits.
1293For any particular hardware, impossible speed changes are
1294ignored.
1295To retrieve the input speed in the
1296.Vt termios
1297structure pointed to
1298by
1299.Fa termios_p
1300see the following code segment.
1301.Bd -literal -offset 2n
1302speed_t ispeed;
1303if (termios_p->c_cflag & CIBAUDEXT) {
1304 ispeed = ((termios_p->c_cflag & CIBAUD) >> IBSHIFT)
1305 + (CIBAUD >> IBSHIFT) + 1;
1306} else {
1307 ispeed = (termios_p->c_cflag & CIBAUD) >> IBSHIFT;
1308}
1309.Ed
1310.Pp
1311To store the input speed in the
1312.Vt termios
1313structure pointed to by
1314.Fa termios_p
1315see the following code segment.
1316.Bd -literal -offset 2n
1317speed_t ispeed;
1318if (ispeed == 0) {
1319 ispeed = termios_p->c_cflag & CBAUD;
1320 if (termios_p->c_cflag & CBAUDEXT)
1321     ispeed += (CBAUD + 1);
1322}
1323if ((ispeed << IBSHIFT) > CIBAUD) {
1324  termios_p->c_cflag |= CIBAUDEXT;
1325  ispeed -= ((CIBAUD >> IBSHIFT) + 1);
1326} else {
1327  termios_p->c_cflag &= ~CIBAUDEXT;
1328}
1329termios_p->c_cflag =
1330  (termios_p->c_cflag & ~CIBAUD) | ((ispeed << IBSHIFT) & CIBAUD);
1331.Ed
1332.Pp
1333The
1334.Dv CSIZE
1335bits specify the character size in bits for both transmission and reception.
1336This size does not include the parity bit, if any.
1337If
1338.Dv CSTOPB
1339is set, two stop bits are used; otherwise, one stop bit is used.
1340For example, at 110 baud, two stops bits are required.
1341.Pp
1342If
1343.Dv PARENB
1344is set, parity generation and detection is enabled, and a
1345parity bit is added to each character.
1346If parity is enabled, the
1347.Dv PARODD
1348flag specifies odd parity if set; otherwise, even parity is used.
1349.Pp
1350If
1351.Dv CREAD
1352is set, the receiver is enabled.
1353Otherwise, no characters are received.
1354.Pp
1355If
1356.Dv HUPCL
1357is set, the line is disconnected when the last process with the
1358line open closes it or terminates.
1359That is, the data-terminal-ready signal is not asserted.
1360.Pp
1361If
1362.Dv CLOCAL
1363is set, the line is assumed to be a local, direct connection
1364with no modem control; otherwise, modem control is assumed.
1365.Pp
1366If
1367.Dv CRTSXOFF
1368is set, inbound hardware flow control is enabled.
1369.Pp
1370If
1371.Dv CRTSCTS
1372is set, outbound hardware flow control is enabled.
1373.Pp
1374The four possible combinations for the state of
1375.Dv CRTSCTS
1376and
1377.Dv CRTSXOFF
1378bits and their interactions are described below.
1379.Bl -tag -width "Case C:"
1380.It Sy Case A :
1381.Dv CRTSCTS
1382off,
1383.Dv CRTSXOFF
1384off.
1385In this case the hardware flow control is disabled.
1386.It Sy Case B :
1387.Dv CRTSCTS
1388on,
1389.Dv CRTSXOFF
1390off.
1391In this case only outbound hardware flow control is enabled.
1392The state of CTS signal is used to do outbound flow control.
1393It is expected that output will be suspended if CTS is low and resumed
1394when CTS is high.
1395.It Sy Case C :
1396.Dv CRTSCTS
1397off,
1398.Dv CRTSXOFF
1399on.
1400In this case only inbound hardware flow control is enabled.
1401The state of RTS signal is used to do inbound flow control.
1402It is expected that input will be suspended if RTS is low and resumed when RTS
1403is high.
1404.It Sy Case D :
1405.Dv CRTSCTS
1406on,
1407.Dv CRTSXOFF
1408on.
1409In this case both inbound and outbound hardware flow control are enabled.
1410Uses the state of CTS signal to do outbound
1411flow control and RTS signal to do inbound flow control.
1412.El
1413.Ss "Local Modes"
1414The
1415.Fa c_lflag
1416field of the argument structure is used by the line
1417discipline to control terminal functions.
1418The basic line discipline provides the following:
1419.Pp
1420.Bl -tag -offset 2n -width SIGTTOU -compact
1421.It Dv ISIG
1422Enable signals.
1423.It Dv ICANON
1424Canonical input (erase and kill processing).
1425.It Dv XCASE
1426Canonical upper/lower presentation.
1427.It Dv ECHO
1428Enable echo.
1429.It Dv ECHOE
1430Echo erase character as
1431.Sy BS Ns - Ns Sy SP Ns - Ns Sy BS
1432&.
1433.It Dv ECHOK
1434Echo
1435.Sy NL
1436after kill character.
1437.It Dv ECHONL
1438Echo
1439.Sy NL .
1440.It Dv NOFLSH
1441Disable flush after interrupt or quit.
1442.It Dv TOSTOP
1443Send
1444.It Dv SIGTTOU
1445for background output.
1446.It Dv ECHOCTL
1447Echo control characters as
1448.Em char ,
1449delete as ^?.
1450.It Dv ECHOPRT
1451Echo erase character as character erased.
1452.It Dv ECHOKE
1453.Sy BS Ns - Ns Sy SP Ns - Ns Sy BS
1454erase entire line on line kill.
1455.It Dv FLUSHO
1456Output is being flushed.
1457.It Dv PENDIN
1458Retype pending input at next read or input character.
1459.It Dv IEXTEN
1460Enable extended (implementation-defined) functions.
1461.El
1462.Pp
1463If
1464.Dv ISIG
1465is set, each input character is checked against the special
1466control characters
1467.Sy INTR ,
1468.Sy QUIT ,
1469.Sy SWTCH ,
1470.Sy SUSP ,
1471.Sy STATUS ,
1472and
1473.Sy DSUSP .
1474If an input character matches one of these control characters, the function
1475associated with that character is performed.
1476.Po
1477Note: If
1478.Sy SWTCH
1479is set and the character matches, the character is simply discarded.
1480No other action is taken.
1481.Pc
1482If
1483.Dv ISIG
1484is not set, no checking is done.
1485Thus, these special
1486input functions are possible only if
1487.Dv ISIG
1488is set.
1489.Pp
1490If
1491.Dv ICANON
1492is set, canonical processing is enabled.
1493This enables the erase
1494and kill edit functions, and the assembly of input characters into lines
1495delimited by
1496.Sy NL-c ,
1497.Sy EOF ,
1498.Sy EOL ,
1499and
1500.Sy EOL .
1501If
1502.Dv ICANON
1503is not set, read requests are satisfied directly from the input queue.
1504A read is not satisfied until at least
1505.Sy MIN
1506characters have been received or the timeout value
1507.Sy TIME
1508has expired between characters.
1509This allows fast bursts of input to be read efficiently while still allowing
1510single character input.
1511The time value represents tenths of seconds.
1512.Pp
1513If
1514.Dv XCASE
1515is set and
1516.Dv ICANON
1517is set, an upper case letter is
1518accepted on input if preceded by a backslash
1519.Ql \e
1520character, and is output preceded by a backslash
1521.Ql \e
1522character.
1523In this mode, the
1524following escape sequences are generated on output and accepted on input:
1525.Bl -column "FOR:" "USE:" -offset 2n
1526.It FOR: Ta USE:
1527.It ` Ta \e'
1528.It | Ta \e!
1529.It \(ap Ta \e^
1530.It { Ta \e(
1531.It } Ta \e)
1532.It \e Ta \e\e
1533.El
1534.Pp
1535For example, input A as \ea, \en as \e\en, and \eN as \e\e\en.
1536.Pp
1537If
1538.Dv ECHO
1539is set, characters are echoed as received.
1540.Pp
1541When
1542.Dv ICANON
1543is set, the following echo functions are possible.
1544.Bl -bullet -offset indent
1545.It
1546If
1547.Dv ECHO
1548and
1549.Dv ECHOE
1550are set, and
1551.Dv ECHOPRT
1552is not set, the
1553.Sy ERASE ,
1554.Sy ERASE2 ,
1555and
1556.Sy WERASE
1557characters are echoed as one or
1558more ASCII BS SP BS, which clears the last character(s) from a
1559.Sy CRT
1560screen.
1561.It
1562If
1563.Dv ECHO ,
1564.Dv ECHOPRT ,
1565and
1566.Dv IEXTEN
1567are set, the first
1568.Sy ERASE ,
1569.Sy ERASE2 ,
1570and
1571.Sy WERASE
1572character in a sequence echoes as a backslash
1573.Ql \e ,
1574followed by the characters being erased.
1575Subsequent
1576.Sy ERASE
1577and
1578.Sy WERASE
1579characters echo the characters being erased, in reverse order.
1580The
1581next non-erase character causes a
1582.Ql /
1583(slash) to be typed before it is echoed.
1584.Dv ECHOPRT
1585should be used for hard copy terminals.
1586.It
1587If
1588.Dv ECHOKE
1589and
1590.Dv IEXTEN
1591are set, the kill character is echoed by
1592erasing each character on the line from the screen (using the mechanism
1593selected by
1594.Dv ECHOE
1595and
1596.Dv ECHOPR ) .
1597.It
1598If
1599.Dv ECHOK
1600is set, and
1601.Dv ECHOKE
1602is not set, the
1603.Sy NL
1604character is
1605echoed after the kill character to emphasize that the line is deleted.
1606Note
1607that a
1608.Ql \e
1609(escape) character or an
1610.Sy LNEXT
1611character preceding the erase
1612or kill character removes any special function.
1613.It
1614If
1615.Dv ECHONL
1616is set, the
1617.Sy NL
1618character is echoed even if
1619.Dv ECHO
1620is not set.
1621This is useful for terminals set to local echo (so called
1622half-duplex).
1623.El
1624.Pp
1625If
1626.Dv ECHOCTL
1627and
1628.Dv IEXTEN
1629are set, all control characters (characters
1630with codes between 0 and 37 octal) other than
1631.Sy ASCII TAB ,
1632.Sy ASCII NL ,
1633the
1634.Sy START
1635character, and the
1636.Sy STOP
1637character,
1638.Sy ASCII CR ,
1639and
1640.Sy ASCII BS
1641are echoed as
1642.No ^ Ns Em X ,
1643where
1644.Em X
1645is the character given by adding
1646.Ql 100
1647octal to the code of the control character (so
1648that the character with octal code
1649.Ql 1
1650is echoed as
1651.No ^ Ns Sy A ) ,
1652and the
1653.Sy ASCII DEL
1654character,
1655with code
1656.Ql 177
1657octal, is echoed as
1658.No ^ Ns Sy \&? .
1659.Pp
1660If
1661.Dv NOFLSH
1662is set, the normal flush of the input and output queues
1663associated with the
1664.Sy INTR ,
1665.Sy QUIT ,
1666.Sy STATUS ,
1667and
1668.Sy SUSP
1669characters is not done.
1670This bit should be set when restarting system calls
1671that read from or write to a terminal
1672.Po
1673see
1674.Xr sigaction 2
1675.Pc .
1676.Pp
1677If
1678.Dv TOSTOP
1679and
1680.Dv IEXTEN
1681are set, the signal
1682.Dv SIGTTOU
1683is sent to
1684a process that tries to write to its controlling terminal if it is not in the
1685foreground process group for that terminal.
1686This signal normally stops the process.
1687Otherwise, the output generated by that process is output to the
1688current output stream.
1689Processes that are blocking or ignoring
1690.Dv SIGTTOU
1691signals are excepted and allowed to produce output, if any.
1692.Pp
1693If
1694.Dv FLUSHO
1695and
1696.Dv IEXTEN
1697are set, data written to the terminal is
1698discarded.
1699This bit is set when the
1700.Sy FLUSH
1701character is typed.
1702A program can cancel the effect of typing the
1703.Sy FLUSH
1704character by clearing
1705.Dv FLUSHO .
1706.Pp
1707If
1708.Dv PENDIN
1709and
1710.Dv IEXTEN
1711are set, any input that has not yet been read
1712is reprinted when the next character arrives as input.
1713.Dv PENDIN
1714is then
1715automatically cleared.
1716.Pp
1717If
1718.Dv IEXTEN
1719is set, the following implementation-defined functions are
1720enabled: special characters (
1721.Sy WERASE ,
1722.Sy REPRINT ,
1723.Sy DISCARD ,
1724and
1725.Sy LNEXT )
1726and local flags (
1727.Dv TOSTOP ,
1728.Dv ECHOCTL ,
1729.Dv ECHOPRT ,
1730.Dv ECHOKE ,
1731.Dv FLUSHO ,
1732and
1733.Dv PENDIN ) .
1734.Ss "Minimum and Timeout"
1735The
1736.Sy MIN
1737and
1738.Sy TIME
1739values were described previously, in the
1740subsection,
1741.Sy Non-canonical Mode Input Processing .
1742The initial value of
1743.Sy MIN
1744is 1, and the initial value of
1745.Sy TIME
1746is 0.
1747.Ss "Terminal Size"
1748The number of lines and columns on the terminal's display is specified in the
1749.Vt winsize
1750structure defined by
1751.In sys/termios.h
1752and includes the following members:
1753.Bd -literal -offset 2n
1754unsigned	short ws_row;  /* rows, in characters */
1755unsigned short	ws_col;        /* columns, in characters */
1756unsigned short	ws_xpixel;     /* horizontal size, in pixels */
1757unsigned short	ws_ypixel;     /* vertical size, in pixels */
1758.Ed
1759.Ss "Termio Structure"
1760The SunOS/SVR4
1761.Vt termio
1762structure is used by some
1763.Fn ioctl Ns s ;
1764it is defined by
1765.In sys/termio.h
1766and includes the following members:
1767.Bd -literal -offset 2n
1768unsigned	short	c_iflag;    /* input modes */
1769unsigned	short	c_oflag;    /* output modes */
1770unsigned	short	c_cflag;    /* control modes */
1771unsigned	short	c_lflag;    /* local modes */
1772char			c_line;     /* line discipline */
1773unsigned	char	c_cc[NCC];  /* control chars */
1774.Ed
1775.Pp
1776The special control characters are defined by the array
1777.Fa c_cc .
1778The symbolic name
1779.Dv NCC
1780is the size of the Control-character array and is also
1781defined by
1782.In termio.h .
1783The relative positions, subscript names, and typical
1784default values for each function are as follows:
1785.Bl -column "Relative Positions" "Subscript Names" "Typical Default Values"
1786.It Relative Positions Ta Subscript Names Ta Typical Default Values
1787.It 0 Ta VINTR Ta EXT
1788.It 1 Ta VQUIT Ta FS
1789.It 2 Ta VERASE Ta DEL
1790.It 3 Ta VKILL Ta NAK
1791.It 4 Ta VEOF Ta EOT
1792.It 5 Ta VEOL Ta NUL
1793.It 6 Ta VEOL2 Ta NUL
1794.It 7 Ta Reserved Ta
1795.El
1796.Pp
1797The
1798.Sy MIN
1799values is stored in the
1800.Dv VMIN
1801element of the
1802.Fa c_cc
1803array; the
1804.Sy TIME
1805value is stored in the
1806.Dv VTIME
1807element of the
1808.Fa c_cc
1809array.
1810The
1811.Dv VMIN
1812element is the same element as the
1813.Dv VEOF
1814element; the
1815.Dv VTIME
1816element is the same element as the
1817.Dv VEOL
1818element.
1819.Pp
1820The calls that use the
1821.Va termio
1822structure only affect the flags and control
1823characters that can be stored in the
1824.Vt termio
1825structure; all other flags and control characters are unaffected.
1826.Ss "Modem Lines"
1827On special files representing serial ports, modem control lines can be read.
1828Control lines (if the underlying hardware supports it) may also be changed.
1829Status lines are read-only.
1830The following modem control and status lines may be
1831supported by a device; they are defined by
1832.In sys/termios.h :
1833.Pp
1834.Bl -tag -width "TIOCM_DTR" -compact -offset 2n
1835.It Dv TIOCM_LE
1836line enable
1837.It Dv TIOCM_DTR
1838data terminal ready
1839.It Dv TIOCM_RTS
1840request to send
1841.It Dv TIOCM_ST
1842secondary transmit
1843.It Dv TIOCM_SR
1844secondary receive
1845.It Dv TIOCM_CTS
1846clear to send
1847.It Dv TIOCM_CAR
1848carrier detect
1849.It Dv TIOCM_RNG
1850ring
1851.It Dv TIOCM_DSR
1852data set ready
1853.El
1854.Pp
1855.Dv TIOCM_CD
1856is a synonym for
1857.Dv TIOCM_CAR ,
1858and
1859.Dv TIOCM_RI
1860is a synonym for
1861.Dv TIOCM_RNG .
1862Not all of these are necessarily supported by any
1863particular device; check the manual page for the device in question.
1864.Pp
1865The software carrier mode can be enabled or disabled using the
1866.Dv TIOCSSOFTCAR
1867.Fn ioctl .
1868If the software carrier flag for a line is off,
1869the line pays attention to the hardware carrier detect (DCD) signal.
1870The
1871.Sy tty
1872device associated with the line cannot be opened until
1873.Sy DCD
1874is asserted.
1875If the software carrier flag is on, the line behaves as if
1876.Sy DCD
1877is always asserted.
1878.Pp
1879The software carrier flag is usually turned on for locally connected terminals
1880or other devices, and is off for lines with modems.
1881.Pp
1882To be able to issue the
1883.Dv TIOCGSOFTCAR
1884and
1885.Dv TIOCSSOFTCAR
1886.Fn ioctl
1887calls, the
1888.Sy tty
1889line should be opened with
1890.Dv O_NDELAY
1891so that the
1892.Xr open 2
1893will not wait for the carrier.
1894.Ss "Default Values"
1895The initial
1896.Vt termios
1897values upon driver open is configurable.
1898This is accomplished by setting the "ttymodes" property in the file
1899.Pa /kernel/drv/options.conf .
1900Since this property is assigned during system
1901initialization, any change to the "ttymodes" property will not take effect
1902until the next reboot.
1903The string value assigned to this property should be in
1904the same format as the output of the
1905.Xr stty 1
1906command with the -g option.
1907.Pp
1908If this property is undefined, the following
1909.Vt termios
1910modes are in effect.
1911The initial input control value is
1912.Dv BRKINT ,
1913.Dv ICRNL ,
1914.Dv IXON ,
1915.Dv IMAXBEL .
1916The initial output control value is
1917.Dv OPOST ,
1918.Dv ONLCR ,
1919.Dv TAB3 .
1920The initial hardware control value is
1921.Dv B9600 ,
1922.Dv CS8 ,
1923.Dv CREAD .
1924The initial line-discipline control value is
1925.Dv ISIG ,
1926.Dv ICANON ,
1927.Dv IEXTEN ,
1928.Dv ECHO ,
1929.Dv ECHOK ,
1930.Dv ECHOE ,
1931.Dv ECHOKE ,
1932.Dv ECHOCTL .
1933.Sh IOCTLS
1934The
1935.Fn ioctl Ns s
1936supported by devices and
1937.Sy STREAMS
1938modules providing the
1939.Xr termios 3C
1940interface are listed below.
1941Some calls may not be supported by all devices or modules.
1942The functionality provided by these calls is also
1943available through the preferred function call interface specified on
1944.Nm termios .
1945.Bl -tag -width TIOCSSOFTCAR
1946.It Dv TCGETS
1947The argument is a pointer to a
1948.Vt termios
1949structure.
1950The current terminal parameters are fetched and stored into that structure.
1951.It Dv TCSETS
1952The argument is a pointer to a
1953.Vt termios
1954structure.
1955The current terminal parameters are set from the values stored in that structure.
1956The change is immediate.
1957.It Dv TCSETSW
1958The argument is a pointer to a
1959.Vt termios
1960structure.
1961The current terminal parameters are set from the values stored in that structure.
1962The change occurs after all characters queued for output have been transmitted.
1963This form should be used when changing parameters that affect output.
1964.It Dv TCSETSF
1965The argument is a pointer to a
1966.Vt termios
1967structure.
1968The current terminal parameters are set from the values stored in that structure.
1969The change occurs after all characters queued for output have been transmitted;
1970all characters queued for input are discarded and then the change occurs.
1971.It Dv TCGETA
1972The argument is a pointer to a
1973.Vt termio
1974structure.
1975The current terminal parameters are fetched, and those parameters that can be
1976stored in a
1977.Vt termio
1978structure are stored into that structure.
1979.It Dv TCSETA
1980The argument is a pointer to a
1981.Vt termio
1982structure.
1983Those terminal parameters that can be stored in a
1984.Vt termio
1985structure are set from the values stored in that structure.
1986The change is immediate.
1987.It Dv TCSETAW
1988The argument is a pointer to a
1989.Vt termio
1990structure.
1991Those terminal parameters that can be stored in a
1992.Vt termio
1993structure are set from
1994the values stored in that structure.
1995The change occurs after all characters queued for output have been transmitted.
1996This form should be used when changing parameters that affect output.
1997.It Dv TCSETAF
1998The argument is a pointer to a
1999.Vt termio
2000structure.
2001Those terminal parameters that can be stored in a
2002.Vt termio
2003structure are set from the values stored in that structure.
2004The change occurs after all characters queued
2005for output have been transmitted; all characters queued for input are discarded
2006and then the change occurs.
2007.It Dv TCSBRK
2008The argument is an
2009.Vt int
2010value.
2011Wait for the output to drain.
2012If the argument is
2013.Sy 0 ,
2014then send a break (zero valued bits for 0\&.25 seconds).
2015.It Dv TCXONC
2016Start/stop control.
2017The argument is an
2018.Vt int
2019value.
2020If the argument is
2021.Sy 0 ,
2022suspend output; if
2023.Sy 1 ,
2024restart suspended output; if
2025.Sy 2 ,
2026suspend input; if
2027.Sy 3 ,
2028restart suspended input.
2029.It Dv TCFLSH
2030The argument is an
2031.Vt int
2032value.
2033If the argument is
2034.Sy 0 ,
2035flush the input queue; if
2036.Sy 1 ,
2037flush the output queue; if
2038.Sy 2 ,
2039flush both the input and output queues.
2040.It Dv TIOCGPGRP
2041The argument is a pointer to a
2042.Vt pid_t .
2043Set the value of that
2044.Vt pid_t
2045to the process group
2046.Sy ID
2047of the foreground process group associated with the terminal.
2048See
2049.Xr termios 3C
2050for a description of
2051.Dv TCGETPGRP .
2052.It Dv TIOCSPGRP
2053The argument is a pointer to a
2054.Vt pid_t .
2055Associate the process group whose
2056process group
2057.Sy ID
2058is specified by the value of that
2059.Vt pid_t
2060with the terminal.
2061The new process group value must be in the range of valid process
2062group
2063.Sy ID
2064values.
2065Otherwise, the error
2066.Er EPERM
2067is returned.
2068.It Dv TIOCGSID
2069The argument is a pointer to a
2070.Vt pid_t .
2071The session ID of the terminal is fetched and stored in the
2072.Vt pid_t .
2073.It Dv TIOCGWINSZ
2074The argument is a pointer to a
2075.Vt winsize
2076structure.
2077The terminal driver's
2078notion of the terminal size is stored into that structure.
2079.It Dv TIOCSWINSZ
2080The argument is a pointer to a
2081.Vt winsize
2082structure.
2083The terminal driver's
2084notion of the terminal size is set from the values specified in that structure.
2085If the new sizes are different from the old sizes, a
2086.Dv SIGWINCH
2087signal is set to the process group of the terminal.
2088.It Dv TIOCMBIS
2089The argument is a pointer to an
2090.Vt int
2091whose value is a mask containing modem control lines to be turned on.
2092The control lines whose bits are set in
2093the argument are turned on; no other control lines are affected.
2094.It Dv TIOCMBIC
2095The argument is a pointer to an
2096.Vt int
2097whose value is a mask containing modem control lines to be turned off.
2098The control lines whose bits are set in
2099the argument are turned off; no other control lines are affected.
2100.It Dv TIOCMGET
2101The argument is a pointer to an
2102.Vt int .
2103The current state of the modem
2104status lines is fetched and stored in the
2105.Vt int
2106pointed to by the argument.
2107.It Dv TIOCMSET
2108The argument is a pointer to an
2109.Vt int
2110containing a new set of modem control lines.
2111The modem control lines are turned on or off, depending on
2112whether the bit for that mode is set or clear.
2113.It Dv TIOCSPPS
2114The argument is a pointer to an
2115.Vt int
2116that determines whether pulse-per-second event handling is to be enabled
2117(non-zero) or disabled (zero).
2118If a one-pulse-per-second reference clock is attached to the serial line's data
2119carrier detect input, the local system clock will be calibrated to it.
2120A clock with a high error, that is, a deviation of more than 25 microseconds
2121per tick, is ignored.
2122.It Dv TIOCGPPS
2123The argument is a pointer to an
2124.Vt int ,
2125in which the state of the even handling is returned.
2126The
2127.Vt int
2128is set to a non-zero value if pulse-per-second (PPS) handling has been enabled.
2129Otherwise, it is set to zero.
2130.It Dv TIOCGSOFTCAR
2131The argument is a pointer to an
2132.Vt int
2133whose value is
2134.Sy 1
2135or
2136.Sy 0 ,
2137depending on whether the software carrier detect is turned on or off.
2138.It Dv TIOCSSOFTCAR
2139The argument is a pointer to an
2140.Vt int
2141whose value is
2142.Sy 1
2143or
2144.Sy 0 .
2145The value of the integer should be
2146.Sy 0
2147to turn off software carrier, or
2148.Sy 1
2149to turn it on.
2150.It Dv TIOCGPPSEV
2151The argument is a pointer to a
2152.Vt "struct ppsclockev" .
2153This structure contains the following members:
2154.Bd -literal -offset 2n
2155struct timeval tv;
2156uint32_t serial;
2157.Ed
2158.Pp
2159.Fa tv
2160is the system clock timestamp when the event (pulse on the
2161.Sy DCD
2162pin) occurred.
2163.Fa serial
2164is the ordinal of the event, which each consecutive event
2165being assigned the next ordinal.
2166The first event registered gets a
2167.Fa serial
2168value of
2169.Sy 1 .
2170The
2171.Dv TIOCGPPSEV
2172returns the last event registered; multiple calls will persistently return the
2173same event until a new one is registered.
2174In addition to time stamping and saving the event, if it is of
2175one-second period and of consistently high accuracy, the local system clock
2176will automatically calibrate to it.
2177.El
2178.Sh FILES
2179Files in or under
2180.Pa /dev
2181.Sh SEE ALSO
2182.Xr stty 1 ,
2183.Xr fork 2 ,
2184.Xr getpgid 2 ,
2185.Xr getsid 2 ,
2186.Xr ioctl 2 ,
2187.Xr setsid 2 ,
2188.Xr sigaction 2 ,
2189.Xr signal 3C ,
2190.Xr tcsetpgrp 3C ,
2191.Xr termios 3C ,
2192.Xr signal.h 3HEAD ,
2193.Xr streamio 4I
2194