blob: a6649598ec1710ef74b35a281f38cfdc33189541 [file] [log] [blame]
Soumendra Ganguly97003462020-08-16 10:51:00 -05001/* termios.c -- POSIX terminal I/O module implementation. */
Guido van Rossum9adae8e1994-09-12 10:41:22 +00002
Guido van Rossumca6954a1999-01-14 19:31:42 +00003#include "Python.h"
Guido van Rossum9adae8e1994-09-12 10:41:22 +00004
Martin v. Löwisbe4fea62003-10-31 13:01:24 +00005/* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE
6 is defined, so we define it here. */
7#if defined(__sgi)
8#define CTRL(c) ((c)&037)
9#endif
10
jceaf0a95f22018-01-28 14:00:48 +010011#if defined(__sun)
12/* We could do better. Check issue-32660 */
13#include <sys/filio.h>
14#include <sys/sockio.h>
15#endif
16
Guido van Rossum9adae8e1994-09-12 10:41:22 +000017#include <termios.h>
Fred Drake9b3bc492001-04-04 21:19:26 +000018#include <sys/ioctl.h>
Guido van Rossum1aca4d81998-03-03 22:10:18 +000019
Fred Drake87068f12001-05-11 16:14:17 +000020/* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
Min ho Kim39d87b52019-08-31 06:21:19 +100021 * MDTR, MRI, and MRTS (apparently used internally by some things
Fred Drake87068f12001-05-11 16:14:17 +000022 * defined as macros; these are not used here directly).
23 */
24#ifdef HAVE_SYS_MODEM_H
25#include <sys/modem.h>
26#endif
Neal Norwitz82251032003-05-23 14:35:24 +000027/* HP-UX requires that this be included to pick up TIOCGPGRP and friends */
28#ifdef HAVE_SYS_BSDTTY_H
29#include <sys/bsdtty.h>
30#endif
Fred Drake87068f12001-05-11 16:14:17 +000031
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +030032/*[clinic input]
33module termios
34[clinic start generated code]*/
35/*[clinic end generated code: output=da39a3ee5e6b4b0d input=01105c85d0ca7252]*/
36
37#include "clinic/termios.c.h"
38
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000039PyDoc_STRVAR(termios__doc__,
40"This module provides an interface to the Posix calls for tty I/O control.\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +000041For a complete description of these calls, see the Posix or Unix manual\n\
42pages. It is only available for those Unix versions that support Posix\n\
43termios style tty I/O control.\n\
44\n\
45All functions in this module take a file descriptor fd as their first\n\
46argument. This can be an integer file descriptor, such as returned by\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000047sys.stdin.fileno(), or a file object, such as sys.stdin itself.");
Guido van Rossum9adae8e1994-09-12 10:41:22 +000048
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010049typedef struct {
50 PyObject *TermiosError;
51} termiosmodulestate;
Hai Shif707d942020-03-16 21:15:01 +080052
53static inline termiosmodulestate*
54get_termios_state(PyObject *module)
55{
56 void *state = PyModule_GetState(module);
57 assert(state != NULL);
58 return (termiosmodulestate *)state;
59}
60
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010061static struct PyModuleDef termiosmodule;
62
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +030063/*[clinic input]
64termios.tcgetattr
65
66 fd: fildes
67 /
68
69Get the tty attributes for file descriptor fd.
70
71Returns a list [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]
72where cc is a list of the tty special characters (each a string of
73length 1, except the items with indices VMIN and VTIME, which are
74integers when these fields are defined). The interpretation of the
75flags and the speeds as well as the indexing in the cc array must be
76done using the symbolic constants defined in this module.
77[clinic start generated code]*/
Guido van Rossum1aca4d81998-03-03 22:10:18 +000078
Guido van Rossum9adae8e1994-09-12 10:41:22 +000079static PyObject *
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +030080termios_tcgetattr_impl(PyObject *module, int fd)
81/*[clinic end generated code: output=2b3da39db870e629 input=54dad9779ebe74b1]*/
Guido van Rossum9adae8e1994-09-12 10:41:22 +000082{
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -050083 termiosmodulestate *state = PyModule_GetState(module);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000084 struct termios mode;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -050085 if (tcgetattr(fd, &mode) == -1) {
86 return PyErr_SetFromErrno(state->TermiosError);
87 }
88
89 speed_t ispeed = cfgetispeed(&mode);
90 speed_t ospeed = cfgetospeed(&mode);
91
92 PyObject *cc = PyList_New(NCCS);
93 if (cc == NULL) {
94 return NULL;
95 }
96
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000097 PyObject *v;
98 int i;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000099 for (i = 0; i < NCCS; i++) {
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500100 char ch = (char)mode.c_cc[i];
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000101 v = PyBytes_FromStringAndSize(&ch, 1);
102 if (v == NULL)
103 goto err;
104 PyList_SetItem(cc, i, v);
105 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000106
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000107 /* Convert the MIN and TIME slots to integer. On some systems, the
108 MIN and TIME slots are the same as the EOF and EOL slots. So we
109 only do this in noncanonical input mode. */
110 if ((mode.c_lflag & ICANON) == 0) {
111 v = PyLong_FromLong((long)mode.c_cc[VMIN]);
112 if (v == NULL)
113 goto err;
114 PyList_SetItem(cc, VMIN, v);
115 v = PyLong_FromLong((long)mode.c_cc[VTIME]);
116 if (v == NULL)
117 goto err;
118 PyList_SetItem(cc, VTIME, v);
119 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000120
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000121 if (!(v = PyList_New(7)))
122 goto err;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000123
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000124 PyList_SetItem(v, 0, PyLong_FromLong((long)mode.c_iflag));
125 PyList_SetItem(v, 1, PyLong_FromLong((long)mode.c_oflag));
126 PyList_SetItem(v, 2, PyLong_FromLong((long)mode.c_cflag));
127 PyList_SetItem(v, 3, PyLong_FromLong((long)mode.c_lflag));
128 PyList_SetItem(v, 4, PyLong_FromLong((long)ispeed));
129 PyList_SetItem(v, 5, PyLong_FromLong((long)ospeed));
Zackery Spytz53835e92018-10-28 22:55:20 -0600130 if (PyErr_Occurred()) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000131 Py_DECREF(v);
132 goto err;
133 }
Zackery Spytz53835e92018-10-28 22:55:20 -0600134 PyList_SetItem(v, 6, cc);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000135 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000136 err:
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000137 Py_DECREF(cc);
138 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000139}
140
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300141/*[clinic input]
142termios.tcsetattr
143
144 fd: fildes
145 when: int
146 attributes as term: object
147 /
148
149Set the tty attributes for file descriptor fd.
150
151The attributes to be set are taken from the attributes argument, which
152is a list like the one returned by tcgetattr(). The when argument
153determines when the attributes are changed: termios.TCSANOW to
154change immediately, termios.TCSADRAIN to change after transmitting all
155queued output, or termios.TCSAFLUSH to change after transmitting all
156queued output and discarding all queued input.
157[clinic start generated code]*/
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000158
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000159static PyObject *
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300160termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
161/*[clinic end generated code: output=bcd2b0a7b98a4bf5 input=5dafabdd5a08f018]*/
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000162{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000163 if (!PyList_Check(term) || PyList_Size(term) != 7) {
164 PyErr_SetString(PyExc_TypeError,
165 "tcsetattr, arg 3: must be 7 element list");
166 return NULL;
167 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000168
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000169 /* Get the old mode, in case there are any hidden fields... */
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500170 termiosmodulestate *state = PyModule_GetState(module);
171 struct termios mode;
172 if (tcgetattr(fd, &mode) == -1) {
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100173 return PyErr_SetFromErrno(state->TermiosError);
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500174 }
175
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000176 mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
177 mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
178 mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
179 mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500180 speed_t ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
181 speed_t ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
182 PyObject *cc = PyList_GetItem(term, 6);
183 if (PyErr_Occurred()) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000184 return NULL;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500185 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000186
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000187 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
188 PyErr_Format(PyExc_TypeError,
189 "tcsetattr: attributes[6] must be %d element list",
190 NCCS);
191 return NULL;
192 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000193
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500194 int i;
195 PyObject *v;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000196 for (i = 0; i < NCCS; i++) {
197 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000198
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000199 if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
200 mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
201 else if (PyLong_Check(v))
202 mode.c_cc[i] = (cc_t) PyLong_AsLong(v);
203 else {
204 PyErr_SetString(PyExc_TypeError,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000205 "tcsetattr: elements of attributes must be characters or integers");
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000206 return NULL;
207 }
208 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000209
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000210 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100211 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000212 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100213 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000214 if (tcsetattr(fd, when, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100215 return PyErr_SetFromErrno(state->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000216
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200217 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000218}
219
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300220/*[clinic input]
221termios.tcsendbreak
222
223 fd: fildes
224 duration: int
225 /
226
227Send a break on file descriptor fd.
228
229A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration
230has a system dependent meaning.
231[clinic start generated code]*/
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000232
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000233static PyObject *
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300234termios_tcsendbreak_impl(PyObject *module, int fd, int duration)
235/*[clinic end generated code: output=5945f589b5d3ac66 input=dc2f32417691f8ed]*/
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000236{
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500237 termiosmodulestate *state = PyModule_GetState(module);
238 if (tcsendbreak(fd, duration) == -1) {
239 return PyErr_SetFromErrno(state->TermiosError);
240 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000241
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200242 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000243}
244
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300245/*[clinic input]
246termios.tcdrain
247
248 fd: fildes
249 /
250
251Wait until all output written to file descriptor fd has been transmitted.
252[clinic start generated code]*/
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000253
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000254static PyObject *
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300255termios_tcdrain_impl(PyObject *module, int fd)
256/*[clinic end generated code: output=5fd86944c6255955 input=c99241b140b32447]*/
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000257{
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500258 termiosmodulestate *state = PyModule_GetState(module);
259 if (tcdrain(fd) == -1) {
260 return PyErr_SetFromErrno(state->TermiosError);
261 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000262
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200263 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000264}
265
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300266/*[clinic input]
267termios.tcflush
268
269 fd: fildes
270 queue: int
271 /
272
273Discard queued data on file descriptor fd.
274
275The queue selector specifies which queue: termios.TCIFLUSH for the input
276queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for
277both queues.
278[clinic start generated code]*/
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000279
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000280static PyObject *
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300281termios_tcflush_impl(PyObject *module, int fd, int queue)
282/*[clinic end generated code: output=2424f80312ec2f21 input=0f7d08122ddc07b5]*/
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000283{
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500284 termiosmodulestate *state = PyModule_GetState(module);
285 if (tcflush(fd, queue) == -1) {
286 return PyErr_SetFromErrno(state->TermiosError);
287 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000288
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200289 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000290}
291
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300292/*[clinic input]
293termios.tcflow
294
295 fd: fildes
296 action: int
297 /
298
299Suspend or resume input or output on file descriptor fd.
300
301The action argument can be termios.TCOOFF to suspend output,
302termios.TCOON to restart output, termios.TCIOFF to suspend input,
303or termios.TCION to restart input.
304[clinic start generated code]*/
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000305
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000306static PyObject *
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300307termios_tcflow_impl(PyObject *module, int fd, int action)
308/*[clinic end generated code: output=afd10928e6ea66eb input=c6aff0640b6efd9c]*/
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000309{
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500310 termiosmodulestate *state = PyModule_GetState(module);
311 if (tcflow(fd, action) == -1) {
312 return PyErr_SetFromErrno(state->TermiosError);
313 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000314
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200315 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000316}
317
318static PyMethodDef termios_methods[] =
319{
Serhiy Storchaka1bcaa812020-10-18 17:54:06 +0300320 TERMIOS_TCGETATTR_METHODDEF
321 TERMIOS_TCSETATTR_METHODDEF
322 TERMIOS_TCSENDBREAK_METHODDEF
323 TERMIOS_TCDRAIN_METHODDEF
324 TERMIOS_TCFLUSH_METHODDEF
325 TERMIOS_TCFLOW_METHODDEF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000326 {NULL, NULL}
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000327};
328
Fred Drakedf48d142001-02-27 21:22:39 +0000329
Fred Drake9ef7fa82001-03-01 21:54:49 +0000330#if defined(VSWTCH) && !defined(VSWTC)
331#define VSWTC VSWTCH
332#endif
333
334#if defined(VSWTC) && !defined(VSWTCH)
335#define VSWTCH VSWTC
336#endif
337
Fred Drakedf48d142001-02-27 21:22:39 +0000338static struct constant {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000339 char *name;
340 long value;
Fred Drakedf48d142001-02-27 21:22:39 +0000341} termios_constants[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000342 /* cfgetospeed(), cfsetospeed() constants */
343 {"B0", B0},
344 {"B50", B50},
345 {"B75", B75},
346 {"B110", B110},
347 {"B134", B134},
348 {"B150", B150},
349 {"B200", B200},
350 {"B300", B300},
351 {"B600", B600},
352 {"B1200", B1200},
353 {"B1800", B1800},
354 {"B2400", B2400},
355 {"B4800", B4800},
356 {"B9600", B9600},
357 {"B19200", B19200},
358 {"B38400", B38400},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000359#ifdef B57600
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000360 {"B57600", B57600},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000361#endif
362#ifdef B115200
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000363 {"B115200", B115200},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000364#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000365#ifdef B230400
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000366 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000367#endif
Antoine Pitroua78f74c2010-11-20 20:03:08 +0000368#ifdef B460800
369 {"B460800", B460800},
370#endif
371#ifdef B500000
372 {"B500000", B500000},
373#endif
374#ifdef B576000
375 {"B576000", B576000},
376#endif
377#ifdef B921600
378 {"B921600", B921600},
379#endif
380#ifdef B1000000
381 {"B1000000", B1000000},
382#endif
383#ifdef B1152000
384 {"B1152000", B1152000},
385#endif
386#ifdef B1500000
387 {"B1500000", B1500000},
388#endif
389#ifdef B2000000
390 {"B2000000", B2000000},
391#endif
392#ifdef B2500000
393 {"B2500000", B2500000},
394#endif
395#ifdef B3000000
396 {"B3000000", B3000000},
397#endif
398#ifdef B3500000
399 {"B3500000", B3500000},
400#endif
401#ifdef B4000000
402 {"B4000000", B4000000},
403#endif
404
Fred Drake9ef7fa82001-03-01 21:54:49 +0000405#ifdef CBAUDEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000406 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000407#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000408
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000409 /* tcsetattr() constants */
410 {"TCSANOW", TCSANOW},
411 {"TCSADRAIN", TCSADRAIN},
412 {"TCSAFLUSH", TCSAFLUSH},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000413#ifdef TCSASOFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000414 {"TCSASOFT", TCSASOFT},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000415#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000416
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000417 /* tcflush() constants */
418 {"TCIFLUSH", TCIFLUSH},
419 {"TCOFLUSH", TCOFLUSH},
420 {"TCIOFLUSH", TCIOFLUSH},
Fred Drakedf48d142001-02-27 21:22:39 +0000421
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000422 /* tcflow() constants */
423 {"TCOOFF", TCOOFF},
424 {"TCOON", TCOON},
425 {"TCIOFF", TCIOFF},
426 {"TCION", TCION},
Fred Drakedf48d142001-02-27 21:22:39 +0000427
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000428 /* struct termios.c_iflag constants */
429 {"IGNBRK", IGNBRK},
430 {"BRKINT", BRKINT},
431 {"IGNPAR", IGNPAR},
432 {"PARMRK", PARMRK},
433 {"INPCK", INPCK},
434 {"ISTRIP", ISTRIP},
435 {"INLCR", INLCR},
436 {"IGNCR", IGNCR},
437 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000438#ifdef IUCLC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000439 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000440#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000441 {"IXON", IXON},
442 {"IXANY", IXANY},
443 {"IXOFF", IXOFF},
Thomas Wouters2b305242001-06-15 12:05:44 +0000444#ifdef IMAXBEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000445 {"IMAXBEL", IMAXBEL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000446#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000447
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000448 /* struct termios.c_oflag constants */
449 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000450#ifdef OLCUC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000451 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000452#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000453#ifdef ONLCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000454 {"ONLCR", ONLCR},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000455#endif
Fred Draked85556c2001-03-03 18:08:52 +0000456#ifdef OCRNL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000457 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000458#endif
459#ifdef ONOCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000460 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000461#endif
462#ifdef ONLRET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000463 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000464#endif
465#ifdef OFILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000466 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000467#endif
468#ifdef OFDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000469 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000470#endif
471#ifdef NLDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000472 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000473#endif
474#ifdef CRDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000475 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000476#endif
477#ifdef TABDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000478 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000479#endif
480#ifdef BSDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000481 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000482#endif
483#ifdef VTDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000484 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000485#endif
486#ifdef FFDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000487 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000488#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000489
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000490 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000491#ifdef NL0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000492 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000493#endif
494#ifdef NL1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000495 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000496#endif
497#ifdef CR0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000498 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000499#endif
500#ifdef CR1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000501 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000502#endif
503#ifdef CR2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000504 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000505#endif
506#ifdef CR3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000507 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000508#endif
509#ifdef TAB0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000510 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000511#endif
512#ifdef TAB1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000513 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000514#endif
515#ifdef TAB2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000516 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000517#endif
518#ifdef TAB3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000519 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000520#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000521#ifdef XTABS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000522 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000523#endif
Fred Draked85556c2001-03-03 18:08:52 +0000524#ifdef BS0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000525 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000526#endif
527#ifdef BS1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000528 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000529#endif
530#ifdef VT0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000531 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000532#endif
533#ifdef VT1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000534 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000535#endif
536#ifdef FF0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000537 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000538#endif
539#ifdef FF1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000540 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000541#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000542
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000543 /* struct termios.c_cflag constants */
544 {"CSIZE", CSIZE},
545 {"CSTOPB", CSTOPB},
546 {"CREAD", CREAD},
547 {"PARENB", PARENB},
548 {"PARODD", PARODD},
549 {"HUPCL", HUPCL},
550 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000551#ifdef CIBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000552 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000553#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000554#ifdef CRTSCTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000555 {"CRTSCTS", (long)CRTSCTS},
Fred Drakededbebf2001-03-02 06:50:58 +0000556#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000557
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000558 /* struct termios.c_cflag-related values (character size) */
559 {"CS5", CS5},
560 {"CS6", CS6},
561 {"CS7", CS7},
562 {"CS8", CS8},
Fred Drakedf48d142001-02-27 21:22:39 +0000563
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000564 /* struct termios.c_lflag constants */
565 {"ISIG", ISIG},
566 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000567#ifdef XCASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000568 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000569#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000570 {"ECHO", ECHO},
571 {"ECHOE", ECHOE},
572 {"ECHOK", ECHOK},
573 {"ECHONL", ECHONL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000574#ifdef ECHOCTL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000575 {"ECHOCTL", ECHOCTL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000576#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000577#ifdef ECHOPRT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000578 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000579#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000580#ifdef ECHOKE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000581 {"ECHOKE", ECHOKE},
Thomas Wouters2b305242001-06-15 12:05:44 +0000582#endif
583#ifdef FLUSHO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000584 {"FLUSHO", FLUSHO},
Thomas Wouters2b305242001-06-15 12:05:44 +0000585#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000586 {"NOFLSH", NOFLSH},
587 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000588#ifdef PENDIN
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000589 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000590#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000591 {"IEXTEN", IEXTEN},
Fred Drakedf48d142001-02-27 21:22:39 +0000592
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000593 /* indexes into the control chars array returned by tcgetattr() */
594 {"VINTR", VINTR},
595 {"VQUIT", VQUIT},
596 {"VERASE", VERASE},
597 {"VKILL", VKILL},
598 {"VEOF", VEOF},
599 {"VTIME", VTIME},
600 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000601#ifdef VSWTC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000602 /* The #defines above ensure that if either is defined, both are,
603 * but both may be omitted by the system headers. ;-( */
604 {"VSWTC", VSWTC},
605 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000606#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000607 {"VSTART", VSTART},
608 {"VSTOP", VSTOP},
609 {"VSUSP", VSUSP},
610 {"VEOL", VEOL},
Fred Draked0b625d2001-05-22 15:44:15 +0000611#ifdef VREPRINT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000612 {"VREPRINT", VREPRINT},
Fred Drake87068f12001-05-11 16:14:17 +0000613#endif
Fred Draked0b625d2001-05-22 15:44:15 +0000614#ifdef VDISCARD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000615 {"VDISCARD", VDISCARD},
Fred Drake87068f12001-05-11 16:14:17 +0000616#endif
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000617#ifdef VWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000618 {"VWERASE", VWERASE},
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000619#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000620#ifdef VLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000621 {"VLNEXT", VLNEXT},
Thomas Wouters2b305242001-06-15 12:05:44 +0000622#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000623#ifdef VEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000624 {"VEOL2", VEOL2},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000625#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000626
Fred Drake55a00342001-03-26 17:14:02 +0000627
628#ifdef B460800
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000629 {"B460800", B460800},
Fred Drake55a00342001-03-26 17:14:02 +0000630#endif
Anthony Shaw7dc72b82020-01-04 23:56:31 +1100631#ifdef B500000
632 {"B500000", B500000},
633#endif
634#ifdef B576000
635 { "B576000", B576000},
636#endif
637#ifdef B921600
638 { "B921600", B921600},
639#endif
640#ifdef B1000000
641 { "B1000000", B1000000},
642#endif
643#ifdef B1152000
644 { "B1152000", B1152000},
645#endif
646#ifdef B1500000
647 { "B1500000", B1500000},
648#endif
649#ifdef B2000000
650 { "B2000000", B2000000},
651#endif
652#ifdef B2500000
653 { "B2500000", B2500000},
654#endif
655#ifdef B3000000
656 { "B3000000", B3000000},
657#endif
658#ifdef B3500000
659 { "B3500000", B3500000},
660#endif
661#ifdef B4000000
662 { "B4000000", B4000000},
663#endif
Fred Drake55a00342001-03-26 17:14:02 +0000664#ifdef CBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000665 {"CBAUD", CBAUD},
Fred Drake55a00342001-03-26 17:14:02 +0000666#endif
667#ifdef CDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000668 {"CDEL", CDEL},
Fred Drake55a00342001-03-26 17:14:02 +0000669#endif
670#ifdef CDSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000671 {"CDSUSP", CDSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000672#endif
673#ifdef CEOF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000674 {"CEOF", CEOF},
Fred Drake55a00342001-03-26 17:14:02 +0000675#endif
676#ifdef CEOL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000677 {"CEOL", CEOL},
Fred Drake55a00342001-03-26 17:14:02 +0000678#endif
679#ifdef CEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000680 {"CEOL2", CEOL2},
Fred Drake55a00342001-03-26 17:14:02 +0000681#endif
682#ifdef CEOT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000683 {"CEOT", CEOT},
Fred Drake55a00342001-03-26 17:14:02 +0000684#endif
685#ifdef CERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000686 {"CERASE", CERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000687#endif
688#ifdef CESC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000689 {"CESC", CESC},
Fred Drake55a00342001-03-26 17:14:02 +0000690#endif
691#ifdef CFLUSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000692 {"CFLUSH", CFLUSH},
Fred Drake55a00342001-03-26 17:14:02 +0000693#endif
694#ifdef CINTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000695 {"CINTR", CINTR},
Fred Drake55a00342001-03-26 17:14:02 +0000696#endif
697#ifdef CKILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000698 {"CKILL", CKILL},
Fred Drake55a00342001-03-26 17:14:02 +0000699#endif
700#ifdef CLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000701 {"CLNEXT", CLNEXT},
Fred Drake55a00342001-03-26 17:14:02 +0000702#endif
703#ifdef CNUL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000704 {"CNUL", CNUL},
Fred Drake55a00342001-03-26 17:14:02 +0000705#endif
706#ifdef COMMON
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000707 {"COMMON", COMMON},
Fred Drake55a00342001-03-26 17:14:02 +0000708#endif
709#ifdef CQUIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000710 {"CQUIT", CQUIT},
Fred Drake55a00342001-03-26 17:14:02 +0000711#endif
712#ifdef CRPRNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000713 {"CRPRNT", CRPRNT},
Fred Drake55a00342001-03-26 17:14:02 +0000714#endif
715#ifdef CSTART
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000716 {"CSTART", CSTART},
Fred Drake55a00342001-03-26 17:14:02 +0000717#endif
718#ifdef CSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000719 {"CSTOP", CSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000720#endif
721#ifdef CSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000722 {"CSUSP", CSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000723#endif
724#ifdef CSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000725 {"CSWTCH", CSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000726#endif
727#ifdef CWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000728 {"CWERASE", CWERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000729#endif
730#ifdef EXTA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000731 {"EXTA", EXTA},
Fred Drake55a00342001-03-26 17:14:02 +0000732#endif
733#ifdef EXTB
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000734 {"EXTB", EXTB},
Fred Drake55a00342001-03-26 17:14:02 +0000735#endif
736#ifdef FIOASYNC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000737 {"FIOASYNC", FIOASYNC},
Fred Drake55a00342001-03-26 17:14:02 +0000738#endif
739#ifdef FIOCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000740 {"FIOCLEX", FIOCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000741#endif
742#ifdef FIONBIO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000743 {"FIONBIO", FIONBIO},
Fred Drake55a00342001-03-26 17:14:02 +0000744#endif
745#ifdef FIONCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000746 {"FIONCLEX", FIONCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000747#endif
748#ifdef FIONREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000749 {"FIONREAD", FIONREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000750#endif
751#ifdef IBSHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000752 {"IBSHIFT", IBSHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000753#endif
754#ifdef INIT_C_CC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000755 {"INIT_C_CC", INIT_C_CC},
Fred Drake55a00342001-03-26 17:14:02 +0000756#endif
757#ifdef IOCSIZE_MASK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000758 {"IOCSIZE_MASK", IOCSIZE_MASK},
Fred Drake55a00342001-03-26 17:14:02 +0000759#endif
760#ifdef IOCSIZE_SHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000761 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000762#endif
763#ifdef NCC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000764 {"NCC", NCC},
Fred Drake55a00342001-03-26 17:14:02 +0000765#endif
766#ifdef NCCS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000767 {"NCCS", NCCS},
Fred Drake55a00342001-03-26 17:14:02 +0000768#endif
769#ifdef NSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000770 {"NSWTCH", NSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000771#endif
772#ifdef N_MOUSE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000773 {"N_MOUSE", N_MOUSE},
Fred Drake55a00342001-03-26 17:14:02 +0000774#endif
775#ifdef N_PPP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000776 {"N_PPP", N_PPP},
Fred Drake55a00342001-03-26 17:14:02 +0000777#endif
778#ifdef N_SLIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000779 {"N_SLIP", N_SLIP},
Fred Drake55a00342001-03-26 17:14:02 +0000780#endif
781#ifdef N_STRIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000782 {"N_STRIP", N_STRIP},
Fred Drake55a00342001-03-26 17:14:02 +0000783#endif
784#ifdef N_TTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000785 {"N_TTY", N_TTY},
Fred Drake55a00342001-03-26 17:14:02 +0000786#endif
787#ifdef TCFLSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000788 {"TCFLSH", TCFLSH},
Fred Drake55a00342001-03-26 17:14:02 +0000789#endif
790#ifdef TCGETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000791 {"TCGETA", TCGETA},
Fred Drake55a00342001-03-26 17:14:02 +0000792#endif
793#ifdef TCGETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000794 {"TCGETS", TCGETS},
Fred Drake55a00342001-03-26 17:14:02 +0000795#endif
796#ifdef TCSBRK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000797 {"TCSBRK", TCSBRK},
Fred Drake55a00342001-03-26 17:14:02 +0000798#endif
799#ifdef TCSBRKP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000800 {"TCSBRKP", TCSBRKP},
Fred Drake55a00342001-03-26 17:14:02 +0000801#endif
802#ifdef TCSETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000803 {"TCSETA", TCSETA},
Fred Drake55a00342001-03-26 17:14:02 +0000804#endif
805#ifdef TCSETAF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000806 {"TCSETAF", TCSETAF},
Fred Drake55a00342001-03-26 17:14:02 +0000807#endif
808#ifdef TCSETAW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000809 {"TCSETAW", TCSETAW},
Fred Drake55a00342001-03-26 17:14:02 +0000810#endif
811#ifdef TCSETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000812 {"TCSETS", TCSETS},
Fred Drake55a00342001-03-26 17:14:02 +0000813#endif
814#ifdef TCSETSF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000815 {"TCSETSF", TCSETSF},
Fred Drake55a00342001-03-26 17:14:02 +0000816#endif
817#ifdef TCSETSW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000818 {"TCSETSW", TCSETSW},
Fred Drake55a00342001-03-26 17:14:02 +0000819#endif
820#ifdef TCXONC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000821 {"TCXONC", TCXONC},
Fred Drake55a00342001-03-26 17:14:02 +0000822#endif
823#ifdef TIOCCONS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000824 {"TIOCCONS", TIOCCONS},
Fred Drake55a00342001-03-26 17:14:02 +0000825#endif
826#ifdef TIOCEXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000827 {"TIOCEXCL", TIOCEXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000828#endif
829#ifdef TIOCGETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000830 {"TIOCGETD", TIOCGETD},
Fred Drake55a00342001-03-26 17:14:02 +0000831#endif
832#ifdef TIOCGICOUNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000833 {"TIOCGICOUNT", TIOCGICOUNT},
Fred Drake55a00342001-03-26 17:14:02 +0000834#endif
835#ifdef TIOCGLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000836 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000837#endif
838#ifdef TIOCGPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000839 {"TIOCGPGRP", TIOCGPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000840#endif
841#ifdef TIOCGSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000842 {"TIOCGSERIAL", TIOCGSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000843#endif
844#ifdef TIOCGSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000845 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000846#endif
847#ifdef TIOCGWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000848 {"TIOCGWINSZ", TIOCGWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000849#endif
850#ifdef TIOCINQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000851 {"TIOCINQ", TIOCINQ},
Fred Drake55a00342001-03-26 17:14:02 +0000852#endif
853#ifdef TIOCLINUX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000854 {"TIOCLINUX", TIOCLINUX},
Fred Drake55a00342001-03-26 17:14:02 +0000855#endif
856#ifdef TIOCMBIC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000857 {"TIOCMBIC", TIOCMBIC},
Fred Drake55a00342001-03-26 17:14:02 +0000858#endif
859#ifdef TIOCMBIS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000860 {"TIOCMBIS", TIOCMBIS},
Fred Drake55a00342001-03-26 17:14:02 +0000861#endif
862#ifdef TIOCMGET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000863 {"TIOCMGET", TIOCMGET},
Fred Drake55a00342001-03-26 17:14:02 +0000864#endif
865#ifdef TIOCMIWAIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000866 {"TIOCMIWAIT", TIOCMIWAIT},
Fred Drake55a00342001-03-26 17:14:02 +0000867#endif
868#ifdef TIOCMSET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000869 {"TIOCMSET", TIOCMSET},
Fred Drake55a00342001-03-26 17:14:02 +0000870#endif
871#ifdef TIOCM_CAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000872 {"TIOCM_CAR", TIOCM_CAR},
Fred Drake55a00342001-03-26 17:14:02 +0000873#endif
874#ifdef TIOCM_CD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000875 {"TIOCM_CD", TIOCM_CD},
Fred Drake55a00342001-03-26 17:14:02 +0000876#endif
877#ifdef TIOCM_CTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000878 {"TIOCM_CTS", TIOCM_CTS},
Fred Drake55a00342001-03-26 17:14:02 +0000879#endif
880#ifdef TIOCM_DSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000881 {"TIOCM_DSR", TIOCM_DSR},
Fred Drake55a00342001-03-26 17:14:02 +0000882#endif
883#ifdef TIOCM_DTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000884 {"TIOCM_DTR", TIOCM_DTR},
Fred Drake55a00342001-03-26 17:14:02 +0000885#endif
886#ifdef TIOCM_LE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000887 {"TIOCM_LE", TIOCM_LE},
Fred Drake55a00342001-03-26 17:14:02 +0000888#endif
889#ifdef TIOCM_RI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000890 {"TIOCM_RI", TIOCM_RI},
Fred Drake55a00342001-03-26 17:14:02 +0000891#endif
892#ifdef TIOCM_RNG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000893 {"TIOCM_RNG", TIOCM_RNG},
Fred Drake55a00342001-03-26 17:14:02 +0000894#endif
895#ifdef TIOCM_RTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000896 {"TIOCM_RTS", TIOCM_RTS},
Fred Drake55a00342001-03-26 17:14:02 +0000897#endif
898#ifdef TIOCM_SR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000899 {"TIOCM_SR", TIOCM_SR},
Fred Drake55a00342001-03-26 17:14:02 +0000900#endif
901#ifdef TIOCM_ST
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000902 {"TIOCM_ST", TIOCM_ST},
Fred Drake55a00342001-03-26 17:14:02 +0000903#endif
904#ifdef TIOCNOTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000905 {"TIOCNOTTY", TIOCNOTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000906#endif
907#ifdef TIOCNXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000908 {"TIOCNXCL", TIOCNXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000909#endif
910#ifdef TIOCOUTQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000911 {"TIOCOUTQ", TIOCOUTQ},
Fred Drake55a00342001-03-26 17:14:02 +0000912#endif
913#ifdef TIOCPKT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000914 {"TIOCPKT", TIOCPKT},
Fred Drake55a00342001-03-26 17:14:02 +0000915#endif
916#ifdef TIOCPKT_DATA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000917 {"TIOCPKT_DATA", TIOCPKT_DATA},
Fred Drake55a00342001-03-26 17:14:02 +0000918#endif
919#ifdef TIOCPKT_DOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000920 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000921#endif
922#ifdef TIOCPKT_FLUSHREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000923 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000924#endif
925#ifdef TIOCPKT_FLUSHWRITE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000926 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
Fred Drake55a00342001-03-26 17:14:02 +0000927#endif
928#ifdef TIOCPKT_NOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000929 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000930#endif
931#ifdef TIOCPKT_START
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000932 {"TIOCPKT_START", TIOCPKT_START},
Fred Drake55a00342001-03-26 17:14:02 +0000933#endif
934#ifdef TIOCPKT_STOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000935 {"TIOCPKT_STOP", TIOCPKT_STOP},
Fred Drake55a00342001-03-26 17:14:02 +0000936#endif
937#ifdef TIOCSCTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000938 {"TIOCSCTTY", TIOCSCTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000939#endif
940#ifdef TIOCSERCONFIG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000941 {"TIOCSERCONFIG", TIOCSERCONFIG},
Fred Drake55a00342001-03-26 17:14:02 +0000942#endif
943#ifdef TIOCSERGETLSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000944 {"TIOCSERGETLSR", TIOCSERGETLSR},
Fred Drake55a00342001-03-26 17:14:02 +0000945#endif
946#ifdef TIOCSERGETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000947 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000948#endif
949#ifdef TIOCSERGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000950 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000951#endif
952#ifdef TIOCSERGWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000953 {"TIOCSERGWILD", TIOCSERGWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000954#endif
955#ifdef TIOCSERSETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000956 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000957#endif
958#ifdef TIOCSERSWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000959 {"TIOCSERSWILD", TIOCSERSWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000960#endif
961#ifdef TIOCSER_TEMT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000962 {"TIOCSER_TEMT", TIOCSER_TEMT},
Fred Drake55a00342001-03-26 17:14:02 +0000963#endif
964#ifdef TIOCSETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000965 {"TIOCSETD", TIOCSETD},
Fred Drake55a00342001-03-26 17:14:02 +0000966#endif
967#ifdef TIOCSLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000968 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000969#endif
970#ifdef TIOCSPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000971 {"TIOCSPGRP", TIOCSPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000972#endif
973#ifdef TIOCSSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000974 {"TIOCSSERIAL", TIOCSSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000975#endif
976#ifdef TIOCSSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000977 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000978#endif
979#ifdef TIOCSTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000980 {"TIOCSTI", TIOCSTI},
Fred Drake55a00342001-03-26 17:14:02 +0000981#endif
982#ifdef TIOCSWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000983 {"TIOCSWINSZ", TIOCSWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000984#endif
985#ifdef TIOCTTYGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000986 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000987#endif
988
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000989 /* sentinel */
990 {NULL, 0}
Fred Drakedf48d142001-02-27 21:22:39 +0000991};
992
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100993static int termiosmodule_traverse(PyObject *m, visitproc visit, void *arg) {
Hai Shif707d942020-03-16 21:15:01 +0800994 Py_VISIT(get_termios_state(m)->TermiosError);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100995 return 0;
996}
997
998static int termiosmodule_clear(PyObject *m) {
Hai Shif707d942020-03-16 21:15:01 +0800999 Py_CLEAR(get_termios_state(m)->TermiosError);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001000 return 0;
1001}
1002
1003static void termiosmodule_free(void *m) {
1004 termiosmodule_clear((PyObject *)m);
1005}
Fred Drakedf48d142001-02-27 21:22:39 +00001006
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001007static int
1008termios_exec(PyObject *mod)
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001009{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001010 struct constant *constant = termios_constants;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001011 termiosmodulestate *state = get_termios_state(mod);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001012 state->TermiosError = PyErr_NewException("termios.error", NULL, NULL);
1013 if (state->TermiosError == NULL) {
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001014 return -1;
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001015 }
1016 Py_INCREF(state->TermiosError);
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001017 if (PyModule_AddObject(mod, "error", state->TermiosError) < 0) {
1018 Py_DECREF(state->TermiosError);
1019 return -1;
1020 }
Fred Drakedf48d142001-02-27 21:22:39 +00001021
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001022 while (constant->name != NULL) {
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001023 if (PyModule_AddIntConstant(
1024 mod, constant->name, constant->value) < 0) {
1025 return -1;
1026 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001027 ++constant;
1028 }
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001029 return 0;
1030}
1031
1032static PyModuleDef_Slot termios_slots[] = {
1033 {Py_mod_exec, termios_exec},
1034 {0, NULL}
1035};
1036
1037static struct PyModuleDef termiosmodule = {
1038 PyModuleDef_HEAD_INIT,
1039 .m_name = "termios",
1040 .m_doc = termios__doc__,
1041 .m_size = sizeof(termiosmodulestate),
1042 .m_methods = termios_methods,
1043 .m_slots = termios_slots,
1044 .m_traverse = termiosmodule_traverse,
1045 .m_clear = termiosmodule_clear,
1046 .m_free = termiosmodule_free,
1047};
1048
1049PyMODINIT_FUNC PyInit_termios(void)
1050{
1051 return PyModuleDef_Init(&termiosmodule);
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001052}