]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/ttyutils.h
2 * No copyright is claimed. This code is in the public domain; do with
5 * Written by Karel Zak <kzak@redhat.com>
7 #ifndef UTIL_LINUX_TTYUTILS_H
8 #define UTIL_LINUX_TTYUTILS_H
13 #ifdef HAVE_SYS_IOCTL_H
14 #include <sys/ioctl.h>
16 #ifdef HAVE_SYS_TTYDEFAULTS_H
17 #include <sys/ttydefaults.h>
21 # define TTY_MODE 0620
23 # define TTY_MODE 0600
25 #define TTYGRPNAME "tty" /* name of group to own ttys */
27 /* Some shorthands for control characters. */
28 #define CTL(x) ((x) ^ 0100) /* Assumes ASCII dialect */
29 #define CR CTL('M') /* carriage return */
30 #define NL CTL('J') /* line feed */
31 #define BS CTL('H') /* back space */
32 #define DEL CTL('?') /* delete */
34 /* Defaults for line-editing etc. characters; you may want to change these. */
35 #define DEF_ERASE DEL /* default erase character */
36 #define DEF_INTR CTL('C') /* default interrupt character */
37 #define DEF_QUIT CTL('\\') /* default quit char */
38 #define DEF_KILL CTL('U') /* default kill char */
39 #define DEF_EOF CTL('D') /* default EOF char */
41 #define DEF_SWITCH 0 /* default switch char */
43 /* Fallback for termios->c_cc[] */
45 # define CREPRINT ('r' & 037)
48 # define CDISCARD ('o' & 037)
51 /* Default termios->iflag */
53 # define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY)
56 /* Default termios->oflag */
58 # define TTYDEF_OFLAG (OPOST | ONLCR /*| OXTABS*/)
61 /* Default termios->lflag */
63 # define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
66 /* Default termios->cflag */
68 # define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
71 /* Storage for things detected while the login name was read. */
73 int erase
; /* erase character */
74 int kill
; /* kill character */
75 int eol
; /* end-of-line character */
76 int parity
; /* what parity did we see */
77 int capslock
; /* upper case without lower case */
80 #define INIT_CHARDATA(ptr) do { \
81 (ptr)->erase = DEF_ERASE; \
82 (ptr)->kill = DEF_KILL; \
85 (ptr)->capslock = 0; \
88 extern int get_terminal_dimension(int *cols
, int *lines
);
89 extern int get_terminal_width(int default_width
);
90 extern int get_terminal_type(const char **type
);
91 extern char *get_terminal_default_type(const char *ttyname
, int is_serial
);
92 extern int get_terminal_stdfd(void);
93 extern int get_terminal_name(const char **path
, const char **name
,
96 #define UL_TTY_KEEPCFLAGS (1 << 1)
97 #define UL_TTY_UTF8 (1 << 2)
99 static inline void reset_virtual_console(struct termios
*tp
, int flags
)
101 /* Use defaults of <sys/ttydefaults.h> for base settings */
102 tp
->c_iflag
|= TTYDEF_IFLAG
;
103 tp
->c_oflag
|= TTYDEF_OFLAG
;
104 tp
->c_lflag
|= TTYDEF_LFLAG
;
106 if ((flags
& UL_TTY_KEEPCFLAGS
) == 0) {
108 tp
->c_lflag
&= ~CBAUD
;
110 tp
->c_cflag
|= (B38400
| TTYDEF_CFLAG
);
113 /* Sane setting, allow eight bit characters, no carriage return delay
114 * the same result as `stty sane cr0 pass8'
162 tp
->c_iflag
|= (BRKINT
| ICRNL
| IMAXBEL
);
163 tp
->c_iflag
&= ~(IGNBRK
| INLCR
| IGNCR
| IXOFF
| IUCLC
| IXANY
| ISTRIP
);
164 tp
->c_oflag
|= (OPOST
| ONLCR
| NL0
| CR0
| TAB0
| BS0
| VT0
| FF0
);
165 tp
->c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| \
166 NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
167 tp
->c_lflag
|= (ISIG
| ICANON
| IEXTEN
| ECHO
|ECHOE
|ECHOK
|ECHOKE
|ECHOCTL
);
168 tp
->c_lflag
&= ~(ECHONL
|ECHOPRT
| NOFLSH
| TOSTOP
);
170 if ((flags
& UL_TTY_KEEPCFLAGS
) == 0) {
171 tp
->c_cflag
|= (CREAD
| CS8
| HUPCL
);
172 tp
->c_cflag
&= ~(PARODD
| PARENB
);
175 tp
->c_oflag
&= ~OFDEL
;
178 tp
->c_lflag
&= ~XCASE
;
181 if (flags
& UL_TTY_UTF8
)
182 tp
->c_iflag
|= IUTF8
; /* Set UTF-8 input flag */
184 tp
->c_iflag
&= ~IUTF8
;
186 /* VTIME and VMIN can overlap with VEOF and VEOL since they are
187 * only used for non-canonical mode. We just set the at the
188 * beginning, so nothing bad should happen.
192 tp
->c_cc
[VINTR
] = CINTR
;
193 tp
->c_cc
[VQUIT
] = CQUIT
;
194 tp
->c_cc
[VERASE
] = CERASE
; /* ASCII DEL (0177) */
195 tp
->c_cc
[VKILL
] = CKILL
;
196 tp
->c_cc
[VEOF
] = CEOF
;
198 tp
->c_cc
[VSWTC
] = _POSIX_VDISABLE
;
199 #elif defined(VSWTCH)
200 tp
->c_cc
[VSWTCH
] = _POSIX_VDISABLE
;
202 tp
->c_cc
[VSTART
] = CSTART
;
203 tp
->c_cc
[VSTOP
] = CSTOP
;
204 tp
->c_cc
[VSUSP
] = CSUSP
;
205 tp
->c_cc
[VEOL
] = _POSIX_VDISABLE
;
206 tp
->c_cc
[VREPRINT
] = CREPRINT
;
207 tp
->c_cc
[VDISCARD
] = CDISCARD
;
208 tp
->c_cc
[VWERASE
] = CWERASE
;
209 tp
->c_cc
[VLNEXT
] = CLNEXT
;
210 tp
->c_cc
[VEOL2
] = _POSIX_VDISABLE
;
213 #endif /* UTIL_LINUX_TTYUTILS_H */