add listen-timeout to function as an accept timeout
[socat/sam.git] / xio-termios.c
blob4cddaf9336031299ba99508060d95cb9b73a5854
1 /* source: xio-termios.c */
2 /* Copyright Gerhard Rieger 2001-2008 */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* this file contains the source for terminal I/O options */
7 #include "xiosysincludes.h"
8 #include "xioopen.h"
10 #include "xio-termios.h"
12 /****** TERMIOS addresses ******/
13 #if _WITH_TERMIOS
14 #if WITH_TERMIOS
15 const struct optdesc opt_tiocsctty={ "tiocsctty", "ctty",OPT_TIOCSCTTY, GROUP_TERMIOS, PH_LATE2, TYPE_BOOL, OFUNC_SPEC };
17 const struct optdesc opt_brkint = { "brkint", NULL, OPT_BRKINT, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, BRKINT };
18 const struct optdesc opt_icrnl = { "icrnl", NULL, OPT_ICRNL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, ICRNL };
19 const struct optdesc opt_ignbrk = { "ignbrk", NULL, OPT_IGNBRK, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IGNBRK };
20 const struct optdesc opt_igncr = { "igncr", NULL, OPT_IGNCR, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IGNCR };
21 const struct optdesc opt_ignpar = { "ignpar", NULL, OPT_IGNPAR, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IGNPAR };
22 const struct optdesc opt_imaxbel = { "imaxbel", NULL, OPT_IMAXBEL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IMAXBEL };
23 const struct optdesc opt_inlcr = { "inlcr", NULL, OPT_INLCR, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, INLCR };
24 const struct optdesc opt_inpck = { "inpck", NULL, OPT_INPCK, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, INPCK };
25 const struct optdesc opt_istrip = { "istrip", NULL, OPT_ISTRIP, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, ISTRIP };
26 #ifdef IUCLC
27 const struct optdesc opt_iuclc = { "iuclc", NULL, OPT_IUCLC, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IUCLC };
28 #endif
29 const struct optdesc opt_ixany = { "ixany", NULL, OPT_IXANY, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IXANY };
30 const struct optdesc opt_ixoff = { "ixoff", NULL, OPT_IXOFF, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IXOFF };
31 const struct optdesc opt_ixon = { "ixon", NULL, OPT_IXON, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, IXON };
32 const struct optdesc opt_parmrk = { "parmrk", NULL, OPT_PARMRK, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 0, PARMRK };
34 #ifdef CRDLY
35 # ifdef CR0
36 const struct optdesc opt_cr0 = { "cr0", NULL, OPT_CR0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, CR0, CRDLY };
37 # endif
38 # ifdef CR1
39 const struct optdesc opt_cr1 = { "cr1", NULL, OPT_CR1, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, CR1, CRDLY };
40 # endif
41 # ifdef CR2
42 const struct optdesc opt_cr2 = { "cr2", NULL, OPT_CR2, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, CR2, CRDLY };
43 # endif
44 # ifdef CR3
45 const struct optdesc opt_cr3 = { "cr3", NULL, OPT_CR3, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, CR3, CRDLY };
46 # endif
47 # if CRDLY_SHIFT >= 0
48 const struct optdesc opt_crdly = { "crdly", NULL, OPT_CRDLY, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_VALUE, 1, CRDLY, CRDLY_SHIFT };
49 # endif
50 #endif /* defined(CRDLY) */
51 #ifdef NLDLY
52 # ifdef NL0
53 const struct optdesc opt_nl0 = { "nl0", NULL, OPT_NL0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, NL0, NLDLY };
54 # endif
55 # ifdef NL1
56 const struct optdesc opt_nl1 = { "nl1", NULL, OPT_NL1, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, NL1, NLDLY };
57 # endif
58 const struct optdesc opt_nldly = { "nldly", NULL, OPT_NLDLY, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, NLDLY };
59 #endif /* defined(NLDLY) */
60 #ifdef OCRNL
61 const struct optdesc opt_ocrnl = { "ocrnl", NULL, OPT_OCRNL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, OCRNL };
62 #endif
63 #ifdef OFDEL
64 const struct optdesc opt_ofdel = { "ofdel", NULL, OPT_OFDEL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, OFDEL };
65 #endif
66 #ifdef OFILL
67 const struct optdesc opt_ofill = { "ofill", NULL, OPT_OFILL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, OFILL };
68 #endif
69 const struct optdesc opt_opost = { "opost", NULL, OPT_OPOST, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, OPOST };
70 #ifdef OLCUC
71 const struct optdesc opt_olcuc = { "olcuc", NULL, OPT_OLCUC, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, OLCUC };
72 #endif
73 const struct optdesc opt_onlcr = { "onlcr", NULL, OPT_ONLCR, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, ONLCR };
74 #ifdef ONLRET
75 const struct optdesc opt_onlret = { "onlret", NULL, OPT_ONLRET, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, ONLRET };
76 #endif
77 #ifdef ONOCR
78 const struct optdesc opt_onocr = { "onocr", NULL, OPT_ONOCR, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, ONOCR };
79 #endif
80 #ifdef TABDLY
81 # ifdef TAB0
82 const struct optdesc opt_tab0 = { "tab0", NULL, OPT_TAB0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_FLAG, 1, TAB0, TABDLY };
83 # endif
84 # ifdef TAB1
85 const struct optdesc opt_tab1 = { "tab1", NULL, OPT_TAB1, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_FLAG, 1, TAB1, TABDLY };
86 # endif
87 # ifdef TAB2
88 const struct optdesc opt_tab2 = { "tab2", NULL, OPT_TAB2, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_FLAG, 1, TAB2, TABDLY };
89 # endif
90 # ifdef TAB3
91 const struct optdesc opt_tab3 = { "tab3", NULL, OPT_TAB3, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_FLAG, 1, TAB3, TABDLY };
92 # endif
93 # ifdef XTABS
94 const struct optdesc opt_xtabs = { "xtabs", NULL, OPT_XTABS, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_FLAG, 1, XTABS, TABDLY };
95 # endif
96 # if TABDLY_SHIFT >= 0
97 const struct optdesc opt_tabdly = { "tabdly", NULL, OPT_TABDLY, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_VALUE, 1, TABDLY, TABDLY_SHIFT };
98 # endif
99 #endif /* defined(TABDLY) */
100 #ifdef BSDLY
101 # ifdef BS0
102 const struct optdesc opt_bs0 = { "bs0", NULL, OPT_BS0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, BS0, BSDLY };
103 #endif
104 # ifdef BS1
105 const struct optdesc opt_bs1 = { "bs1", NULL, OPT_BS1, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, BS1, BSDLY };
106 # endif
107 const struct optdesc opt_bsdly = { "bsdly", NULL, OPT_BSDLY, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, BSDLY };
108 #endif
109 #ifdef VTDLY
110 # ifdef VT0
111 const struct optdesc opt_vt0 = { "vt0", NULL, OPT_VT0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, VT0, VTDLY };
112 # endif
113 # ifdef VT1
114 const struct optdesc opt_vt1 = { "vt1", NULL, OPT_VT1, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, VT1, VTDLY };
115 # endif
116 const struct optdesc opt_vtdly = { "vtdly", NULL, OPT_VTDLY, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, VTDLY };
117 #endif
118 #ifdef FFDLY
119 # ifdef FF0
120 const struct optdesc opt_ff0 = { "ff0", NULL, OPT_FF0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, FF0, FFDLY };
121 # endif
122 # ifdef FF1
123 const struct optdesc opt_ff1 = { "ff1", NULL, OPT_FF1, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, FF1, FFDLY };
124 # endif
125 const struct optdesc opt_ffdly = { "ffdly", NULL, OPT_FFDLY, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 1, FFDLY };
126 #endif
128 #ifdef CBAUD
129 const struct optdesc opt_b0 = { "b0", NULL, OPT_B0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B0, CBAUD };
130 const struct optdesc opt_b50 = { "b50", NULL, OPT_B50, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B50, CBAUD };
131 const struct optdesc opt_b75 = { "b75", NULL, OPT_B75, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B75, CBAUD };
132 const struct optdesc opt_b110 = { "b110", NULL, OPT_B110, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B110, CBAUD };
133 const struct optdesc opt_b134 = { "b134", NULL, OPT_B134, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B134, CBAUD };
134 const struct optdesc opt_b150 = { "b150", NULL, OPT_B150, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B150, CBAUD };
135 const struct optdesc opt_b200 = { "b200", NULL, OPT_B200, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B200, CBAUD };
136 const struct optdesc opt_b300 = { "b300", NULL, OPT_B300, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B300, CBAUD };
137 const struct optdesc opt_b600 = { "b600", NULL, OPT_B600, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B600, CBAUD };
138 #ifdef B900 /* HP-UX */
139 const struct optdesc opt_b900 = { "b900", NULL, OPT_B900, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B900, CBAUD };
140 #endif
141 const struct optdesc opt_b1200 = { "b1200", NULL, OPT_B1200, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B1200, CBAUD };
142 const struct optdesc opt_b1800 = { "b1800", NULL, OPT_B1800, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B1800, CBAUD };
143 const struct optdesc opt_b2400 = { "b2400", NULL, OPT_B2400, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B2400, CBAUD };
144 #ifdef B3600 /* HP-UX */
145 const struct optdesc opt_b3600 = { "b3600", NULL, OPT_B3600, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B3600, CBAUD };
146 #endif
147 const struct optdesc opt_b4800 = { "b4800", NULL, OPT_B4800, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B4800, CBAUD };
148 #ifdef B7200 /* HP-UX */
149 const struct optdesc opt_b7200 = { "b7200", NULL, OPT_B7200, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B7200, CBAUD };
150 #endif
151 const struct optdesc opt_b9600 = { "b9600", NULL, OPT_B9600, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B9600, CBAUD };
152 const struct optdesc opt_b19200 = { "b19200", NULL, OPT_B19200, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B19200, CBAUD };
153 const struct optdesc opt_b38400 = { "b38400", NULL, OPT_B38400, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B38400, CBAUD };
154 #ifdef B57600
155 const struct optdesc opt_b57600 = { "b57600", NULL, OPT_B57600, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B57600, CBAUD };
156 #endif
157 #ifdef B115200
158 const struct optdesc opt_b115200 = { "b115200", NULL, OPT_B115200, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B115200, CBAUD };
159 #endif
160 #ifdef B230400
161 const struct optdesc opt_b230400 = { "b230400", NULL, OPT_B230400, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B230400, CBAUD };
162 #endif
163 #ifdef B460800
164 const struct optdesc opt_b460800 = { "b460800", NULL, OPT_B460800, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B460800, CBAUD };
165 #endif
166 #ifdef B500000
167 const struct optdesc opt_b500000 = { "b500000", NULL, OPT_B500000, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B500000, CBAUD };
168 #endif
169 #ifdef B576000
170 const struct optdesc opt_b576000 = { "b576000", NULL, OPT_B576000, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B576000, CBAUD };
171 #endif
172 #ifdef B921600
173 const struct optdesc opt_b921600 = { "b921600", NULL, OPT_B921600, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B921600, CBAUD };
174 #endif
175 #ifdef B1000000
176 const struct optdesc opt_b1000000= { "b1000000",NULL, OPT_B1000000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B1000000, CBAUD };
177 #endif
178 #ifdef B1152000
179 const struct optdesc opt_b1152000= { "b1152000",NULL, OPT_B1152000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B1152000, CBAUD };
180 #endif
181 #ifdef B1500000
182 const struct optdesc opt_b1500000= { "b1500000",NULL, OPT_B1500000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B1500000, CBAUD };
183 #endif
184 #ifdef B2000000
185 const struct optdesc opt_b2000000= { "b2000000",NULL, OPT_B2000000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B2000000, CBAUD };
186 #endif
187 #ifdef B2500000
188 const struct optdesc opt_b2500000= { "b2500000",NULL, OPT_B2500000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B2500000, CBAUD };
189 #endif
190 #ifdef B3000000
191 const struct optdesc opt_b3000000= { "b3000000",NULL, OPT_B3000000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B3000000, CBAUD };
192 #endif
193 #ifdef B3500000
194 const struct optdesc opt_b3500000= { "b3500000",NULL, OPT_B3500000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B3500000, CBAUD };
195 #endif
196 #ifdef B4000000
197 const struct optdesc opt_b4000000= { "b4000000",NULL, OPT_B4000000,GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, B4000000, CBAUD };
198 #endif
199 #endif /* defined(CBAUD) */
200 const struct optdesc opt_cs5 = { "cs5", NULL, OPT_CS5, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, CS5, CSIZE };
201 const struct optdesc opt_cs6 = { "cs6", NULL, OPT_CS6, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, CS6, CSIZE };
202 const struct optdesc opt_cs7 = { "cs7", NULL, OPT_CS7, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, CS7, CSIZE };
203 const struct optdesc opt_cs8 = { "cs8", NULL, OPT_CS8, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, CS8, CSIZE };
204 #if CSIZE_SHIFT >= 0
205 const struct optdesc opt_csize = { "csize", NULL, OPT_CSIZE, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_VALUE, 2, CSIZE, CSIZE_SHIFT };
206 #endif
207 const struct optdesc opt_cstopb = { "cstopb", NULL, OPT_CSTOPB, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, CSTOPB };
208 const struct optdesc opt_cread = { "cread", NULL, OPT_CREAD, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, CREAD };
209 const struct optdesc opt_parenb = { "parenb", NULL, OPT_PARENB, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, PARENB };
210 const struct optdesc opt_parodd = { "parodd", NULL, OPT_PARODD, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, PARODD };
211 const struct optdesc opt_hupcl = { "hupcl", NULL, OPT_HUPCL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, HUPCL };
212 const struct optdesc opt_clocal = { "clocal", NULL, OPT_CLOCAL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, CLOCAL };
213 /*const struct optdesc opt_cibaud = { "cibaud",NULL, OPT_CIBAUD, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, CIBAUD };*/
214 #ifdef CRTSCTS
215 const struct optdesc opt_crtscts = { "crtscts", NULL, OPT_CRTSCTS, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, CRTSCTS };
216 #endif
218 const struct optdesc opt_isig = { "isig", NULL, OPT_ISIG, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ISIG };
219 const struct optdesc opt_icanon = { "icanon", NULL, OPT_ICANON, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ICANON };
220 #ifdef XCASE
221 const struct optdesc opt_xcase = { "xcase", NULL, OPT_XCASE, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, XCASE };
222 #endif
223 const struct optdesc opt_echo = { "echo", NULL, OPT_ECHO, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ECHO };
224 const struct optdesc opt_echoe = { "echoe", NULL, OPT_ECHOE, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ECHOE };
225 const struct optdesc opt_echok = { "echok", NULL, OPT_ECHOK, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ECHOK };
226 const struct optdesc opt_echonl = { "echonl", NULL, OPT_ECHONL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ECHONL };
227 const struct optdesc opt_echoctl = { "echoctl", NULL, OPT_ECHOCTL, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ECHOCTL };
228 #ifdef ECHOPRT
229 const struct optdesc opt_echoprt = { "echoprt", NULL, OPT_ECHOPRT, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ECHOPRT };
230 #endif
231 const struct optdesc opt_echoke = { "echoke", NULL, OPT_ECHOKE, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, ECHOKE };
232 const struct optdesc opt_flusho = { "flusho", NULL, OPT_FLUSHO, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, FLUSHO };
233 const struct optdesc opt_noflsh = { "noflsh", NULL, OPT_NOFLSH, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, NOFLSH };
234 const struct optdesc opt_tostop = { "tostop", NULL, OPT_TOSTOP, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, TOSTOP };
235 #ifdef PENDIN
236 const struct optdesc opt_pendin = { "pendin", NULL, OPT_PENDIN, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, PENDIN };
237 #endif
238 const struct optdesc opt_iexten = { "iexten", NULL, OPT_IEXTEN, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 3, IEXTEN };
240 const struct optdesc opt_vintr = { "vintr", "intr", OPT_VINTR, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VINTR };
241 const struct optdesc opt_vquit = { "vquit", "quit", OPT_VQUIT, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VQUIT };
242 const struct optdesc opt_verase = { "verase", "erase", OPT_VERASE, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VERASE };
243 const struct optdesc opt_vkill = { "vkill", "kill", OPT_VKILL, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VKILL };
244 const struct optdesc opt_veof = { "veof", "eof", OPT_VEOF, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VEOF };
245 const struct optdesc opt_vtime = { "vtime", "time", OPT_VTIME, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VTIME };
246 const struct optdesc opt_vmin = { "vmin", "min", OPT_VMIN, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VMIN };
247 #ifdef VSWTC
248 const struct optdesc opt_vswtc = { "vswtc", "swtc", OPT_VSWTC, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VSWTC };
249 #endif /* VSWTC */
250 const struct optdesc opt_vstart = { "vstart", "start", OPT_VSTART, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VSTART };
251 const struct optdesc opt_vstop = { "vstop", "stop", OPT_VSTOP, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VSTOP };
252 const struct optdesc opt_vsusp = { "vsusp", "susp", OPT_VSUSP, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VSUSP };
253 #ifdef VDSUSP /* HP-UX */
254 const struct optdesc opt_vdsusp = { "vdsusp", "dsusp", OPT_VDSUSP, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VDSUSP };
255 #endif
256 const struct optdesc opt_veol = { "veol", "eol", OPT_VEOL, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VEOL };
257 #ifdef VREPRINT
258 const struct optdesc opt_vreprint = { "vreprint","reprint",OPT_VREPRINT,GROUP_TERMIOS,PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VREPRINT };
259 #endif
260 #ifdef VDISCARD
261 const struct optdesc opt_vdiscard = { "vdiscard","discard",OPT_VDISCARD,GROUP_TERMIOS,PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VDISCARD };
262 #endif
263 #ifdef VWERASE
264 const struct optdesc opt_vwerase = { "vwerase","werase",OPT_VWERASE, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VWERASE };
265 #endif
266 const struct optdesc opt_vlnext = { "vlnext", "lnext", OPT_VLNEXT, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VLNEXT };
267 const struct optdesc opt_veol2 = { "veol2", "eol2", OPT_VEOL2, GROUP_TERMIOS, PH_FD, TYPE_BYTE, OFUNC_TERMIOS_CHAR, VEOL2 };
269 const struct optdesc opt_raw = { "raw", NULL, OPT_RAW, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_SPEC };
270 const struct optdesc opt_sane = { "sane", NULL, OPT_SANE, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_SPEC };
272 #ifdef HAVE_TERMIOS_ISPEED
273 const struct optdesc opt_ispeed = { "ispeed", NULL, OPT_ISPEED, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_SPEED, ISPEED_OFFSET };
274 const struct optdesc opt_ospeed = { "ospeed", NULL, OPT_OSPEED, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_SPEED, OSPEED_OFFSET };
275 #endif /* HAVE_TERMIOS_ISPEED */
278 int xiotermiosflag_applyopt(int fd, struct opt *opt) {
279 int result;
280 if (opt->value.u_bool) {
281 result = xiotermios_setflag(fd, opt->desc->major, opt->desc->minor);
282 } else {
283 result = xiotermios_clrflag(fd, opt->desc->major, opt->desc->minor);
285 if (result < 0) {
286 opt->desc = ODESC_ERROR;
287 return -1;
289 return 0;
292 #endif /* WITH_TERMIOS */
294 int xiotermios_setflag(int fd, int word, tcflag_t mask) {
295 union {
296 struct termios termarg;
297 tcflag_t flags[4];
298 } tdata;
300 if (Tcgetattr(fd, &tdata.termarg) < 0) {
301 Error3("tcgetattr(%d, %p): %s",
302 fd, &tdata.termarg, strerror(errno));
303 return -1;
305 tdata.flags[word] |= mask;
306 if (Tcsetattr(fd, TCSADRAIN, &tdata.termarg) < 0) {
307 Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
308 fd, &tdata.termarg, strerror(errno));
309 return -1;
311 return 0;
314 int xiotermios_clrflag(int fd, int word, tcflag_t mask) {
315 union {
316 struct termios termarg;
317 tcflag_t flags[4];
318 } tdata;
320 if (Tcgetattr(fd, &tdata.termarg) < 0) {
321 Error3("tcgetattr(%d, %p): %s",
322 fd, &tdata.termarg, strerror(errno));
323 return -1;
325 tdata.flags[word] &= ~mask;
326 if (Tcsetattr(fd, TCSADRAIN, &tdata.termarg) < 0) {
327 Error3("tcsetattr(%d, TCSADRAIN, %p): %s",
328 fd, &tdata.termarg, strerror(errno));
329 return -1;
331 return 0;
334 #endif /* _WITH_TERMIOS */