blob: 75e5e523206f418eef009c0a54f3adf6a1c90e77 [file] [log] [blame]
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001/* termiosmodule.c -- POSIX terminal I/O module implementation. */
2
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
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000032PyDoc_STRVAR(termios__doc__,
33"This module provides an interface to the Posix calls for tty I/O control.\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +000034For a complete description of these calls, see the Posix or Unix manual\n\
35pages. It is only available for those Unix versions that support Posix\n\
36termios style tty I/O control.\n\
37\n\
38All functions in this module take a file descriptor fd as their first\n\
39argument. This can be an integer file descriptor, such as returned by\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000040sys.stdin.fileno(), or a file object, such as sys.stdin itself.");
Guido van Rossum9adae8e1994-09-12 10:41:22 +000041
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010042typedef struct {
43 PyObject *TermiosError;
44} termiosmodulestate;
Hai Shif707d942020-03-16 21:15:01 +080045
46static inline termiosmodulestate*
47get_termios_state(PyObject *module)
48{
49 void *state = PyModule_GetState(module);
50 assert(state != NULL);
51 return (termiosmodulestate *)state;
52}
53
54#define modulestate_global get_termios_state(PyState_FindModule(&termiosmodule))
Guido van Rossum9adae8e1994-09-12 10:41:22 +000055
Fred Drakeb638aaf2001-05-07 17:55:35 +000056static int fdconv(PyObject* obj, void* p)
57{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000058 int fd;
Fred Drakeb638aaf2001-05-07 17:55:35 +000059
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000060 fd = PyObject_AsFileDescriptor(obj);
61 if (fd >= 0) {
62 *(int*)p = fd;
63 return 1;
64 }
65 return 0;
Fred Drakeb638aaf2001-05-07 17:55:35 +000066}
Guido van Rossum9adae8e1994-09-12 10:41:22 +000067
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010068static struct PyModuleDef termiosmodule;
69
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000070PyDoc_STRVAR(termios_tcgetattr__doc__,
71"tcgetattr(fd) -> list_of_attrs\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +000072\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +000073Get the tty attributes for file descriptor fd, as follows:\n\
74[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
75of the tty special characters (each a string of length 1, except the items\n\
76with indices VMIN and VTIME, which are integers when these fields are\n\
77defined). The interpretation of the flags and the speeds as well as the\n\
78indexing in the cc array must be done using the symbolic constants defined\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000079in this module.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +000080
Guido van Rossum9adae8e1994-09-12 10:41:22 +000081static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +000082termios_tcgetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000083{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000084 int fd;
85 struct termios mode;
86 PyObject *cc;
87 speed_t ispeed, ospeed;
88 PyObject *v;
89 int i;
90 char ch;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000091
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000092 if (!PyArg_ParseTuple(args, "O&:tcgetattr",
93 fdconv, (void*)&fd))
94 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000095
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000096 if (tcgetattr(fd, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010097 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000098
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000099 ispeed = cfgetispeed(&mode);
100 ospeed = cfgetospeed(&mode);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000101
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000102 cc = PyList_New(NCCS);
103 if (cc == NULL)
104 return NULL;
105 for (i = 0; i < NCCS; i++) {
106 ch = (char)mode.c_cc[i];
107 v = PyBytes_FromStringAndSize(&ch, 1);
108 if (v == NULL)
109 goto err;
110 PyList_SetItem(cc, i, v);
111 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000112
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000113 /* Convert the MIN and TIME slots to integer. On some systems, the
114 MIN and TIME slots are the same as the EOF and EOL slots. So we
115 only do this in noncanonical input mode. */
116 if ((mode.c_lflag & ICANON) == 0) {
117 v = PyLong_FromLong((long)mode.c_cc[VMIN]);
118 if (v == NULL)
119 goto err;
120 PyList_SetItem(cc, VMIN, v);
121 v = PyLong_FromLong((long)mode.c_cc[VTIME]);
122 if (v == NULL)
123 goto err;
124 PyList_SetItem(cc, VTIME, v);
125 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000126
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000127 if (!(v = PyList_New(7)))
128 goto err;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000129
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000130 PyList_SetItem(v, 0, PyLong_FromLong((long)mode.c_iflag));
131 PyList_SetItem(v, 1, PyLong_FromLong((long)mode.c_oflag));
132 PyList_SetItem(v, 2, PyLong_FromLong((long)mode.c_cflag));
133 PyList_SetItem(v, 3, PyLong_FromLong((long)mode.c_lflag));
134 PyList_SetItem(v, 4, PyLong_FromLong((long)ispeed));
135 PyList_SetItem(v, 5, PyLong_FromLong((long)ospeed));
Zackery Spytz53835e92018-10-28 22:55:20 -0600136 if (PyErr_Occurred()) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000137 Py_DECREF(v);
138 goto err;
139 }
Zackery Spytz53835e92018-10-28 22:55:20 -0600140 PyList_SetItem(v, 6, cc);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000141 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000142 err:
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000143 Py_DECREF(cc);
144 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000145}
146
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000147PyDoc_STRVAR(termios_tcsetattr__doc__,
148"tcsetattr(fd, when, attributes) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000149\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000150Set the tty attributes for file descriptor fd.\n\
151The attributes to be set are taken from the attributes argument, which\n\
152is a list like the one returned by tcgetattr(). The when argument\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000153determines when the attributes are changed: termios.TCSANOW to\n\
154change immediately, termios.TCSADRAIN to change after transmitting all\n\
155queued output, or termios.TCSAFLUSH to change after transmitting all\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000156queued output and discarding all queued input. ");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000157
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000158static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000159termios_tcsetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000160{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000161 int fd, when;
162 struct termios mode;
163 speed_t ispeed, ospeed;
164 PyObject *term, *cc, *v;
165 int i;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000166
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000167 if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
168 fdconv, &fd, &when, &term))
169 return NULL;
170 if (!PyList_Check(term) || PyList_Size(term) != 7) {
171 PyErr_SetString(PyExc_TypeError,
172 "tcsetattr, arg 3: must be 7 element list");
173 return NULL;
174 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000175
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000176 /* Get the old mode, in case there are any hidden fields... */
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100177 termiosmodulestate *state = modulestate_global;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000178 if (tcgetattr(fd, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100179 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000180 mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
181 mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
182 mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
183 mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
184 ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
185 ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
186 cc = PyList_GetItem(term, 6);
187 if (PyErr_Occurred())
188 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000189
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000190 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
191 PyErr_Format(PyExc_TypeError,
192 "tcsetattr: attributes[6] must be %d element list",
193 NCCS);
194 return NULL;
195 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000196
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000197 for (i = 0; i < NCCS; i++) {
198 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000199
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000200 if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
201 mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
202 else if (PyLong_Check(v))
203 mode.c_cc[i] = (cc_t) PyLong_AsLong(v);
204 else {
205 PyErr_SetString(PyExc_TypeError,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000206 "tcsetattr: elements of attributes must be characters or integers");
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000207 return NULL;
208 }
209 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000210
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000211 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100212 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000213 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100214 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000215 if (tcsetattr(fd, when, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100216 return PyErr_SetFromErrno(state->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000217
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200218 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000219}
220
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000221PyDoc_STRVAR(termios_tcsendbreak__doc__,
222"tcsendbreak(fd, duration) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000223\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000224Send a break on file descriptor fd.\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000225A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000226has a system dependent meaning.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000227
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000228static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000229termios_tcsendbreak(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000230{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000231 int fd, duration;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000232
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000233 if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
234 fdconv, &fd, &duration))
235 return NULL;
236 if (tcsendbreak(fd, duration) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100237 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000238
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200239 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000240}
241
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000242PyDoc_STRVAR(termios_tcdrain__doc__,
243"tcdrain(fd) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000244\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000245Wait until all output written to file descriptor fd has been transmitted.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000246
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000247static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000248termios_tcdrain(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000249{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000250 int fd;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000251
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000252 if (!PyArg_ParseTuple(args, "O&:tcdrain",
253 fdconv, &fd))
254 return NULL;
255 if (tcdrain(fd) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100256 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000257
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200258 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000259}
260
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000261PyDoc_STRVAR(termios_tcflush__doc__,
262"tcflush(fd, queue) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000263\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000264Discard queued data on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000265The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
266queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000267both queues. ");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000268
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000269static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000270termios_tcflush(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000271{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000272 int fd, queue;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000273
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000274 if (!PyArg_ParseTuple(args, "O&i:tcflush",
275 fdconv, &fd, &queue))
276 return NULL;
277 if (tcflush(fd, queue) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100278 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000279
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200280 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000281}
282
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000283PyDoc_STRVAR(termios_tcflow__doc__,
284"tcflow(fd, action) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000285\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000286Suspend or resume input or output on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000287The action argument can be termios.TCOOFF to suspend output,\n\
288termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000289or termios.TCION to restart input.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000290
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000291static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000292termios_tcflow(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000293{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000294 int fd, action;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000295
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000296 if (!PyArg_ParseTuple(args, "O&i:tcflow",
297 fdconv, &fd, &action))
298 return NULL;
299 if (tcflow(fd, action) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100300 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000301
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200302 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000303}
304
305static PyMethodDef termios_methods[] =
306{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000307 {"tcgetattr", termios_tcgetattr,
308 METH_VARARGS, termios_tcgetattr__doc__},
309 {"tcsetattr", termios_tcsetattr,
310 METH_VARARGS, termios_tcsetattr__doc__},
311 {"tcsendbreak", termios_tcsendbreak,
312 METH_VARARGS, termios_tcsendbreak__doc__},
313 {"tcdrain", termios_tcdrain,
314 METH_VARARGS, termios_tcdrain__doc__},
315 {"tcflush", termios_tcflush,
316 METH_VARARGS, termios_tcflush__doc__},
317 {"tcflow", termios_tcflow,
318 METH_VARARGS, termios_tcflow__doc__},
319 {NULL, NULL}
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000320};
321
Fred Drakedf48d142001-02-27 21:22:39 +0000322
Fred Drake9ef7fa82001-03-01 21:54:49 +0000323#if defined(VSWTCH) && !defined(VSWTC)
324#define VSWTC VSWTCH
325#endif
326
327#if defined(VSWTC) && !defined(VSWTCH)
328#define VSWTCH VSWTC
329#endif
330
Fred Drakedf48d142001-02-27 21:22:39 +0000331static struct constant {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000332 char *name;
333 long value;
Fred Drakedf48d142001-02-27 21:22:39 +0000334} termios_constants[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000335 /* cfgetospeed(), cfsetospeed() constants */
336 {"B0", B0},
337 {"B50", B50},
338 {"B75", B75},
339 {"B110", B110},
340 {"B134", B134},
341 {"B150", B150},
342 {"B200", B200},
343 {"B300", B300},
344 {"B600", B600},
345 {"B1200", B1200},
346 {"B1800", B1800},
347 {"B2400", B2400},
348 {"B4800", B4800},
349 {"B9600", B9600},
350 {"B19200", B19200},
351 {"B38400", B38400},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000352#ifdef B57600
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000353 {"B57600", B57600},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000354#endif
355#ifdef B115200
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000356 {"B115200", B115200},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000357#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000358#ifdef B230400
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000359 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000360#endif
Antoine Pitroua78f74c2010-11-20 20:03:08 +0000361#ifdef B460800
362 {"B460800", B460800},
363#endif
364#ifdef B500000
365 {"B500000", B500000},
366#endif
367#ifdef B576000
368 {"B576000", B576000},
369#endif
370#ifdef B921600
371 {"B921600", B921600},
372#endif
373#ifdef B1000000
374 {"B1000000", B1000000},
375#endif
376#ifdef B1152000
377 {"B1152000", B1152000},
378#endif
379#ifdef B1500000
380 {"B1500000", B1500000},
381#endif
382#ifdef B2000000
383 {"B2000000", B2000000},
384#endif
385#ifdef B2500000
386 {"B2500000", B2500000},
387#endif
388#ifdef B3000000
389 {"B3000000", B3000000},
390#endif
391#ifdef B3500000
392 {"B3500000", B3500000},
393#endif
394#ifdef B4000000
395 {"B4000000", B4000000},
396#endif
397
Fred Drake9ef7fa82001-03-01 21:54:49 +0000398#ifdef CBAUDEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000399 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000400#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000401
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000402 /* tcsetattr() constants */
403 {"TCSANOW", TCSANOW},
404 {"TCSADRAIN", TCSADRAIN},
405 {"TCSAFLUSH", TCSAFLUSH},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000406#ifdef TCSASOFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000407 {"TCSASOFT", TCSASOFT},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000408#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000409
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000410 /* tcflush() constants */
411 {"TCIFLUSH", TCIFLUSH},
412 {"TCOFLUSH", TCOFLUSH},
413 {"TCIOFLUSH", TCIOFLUSH},
Fred Drakedf48d142001-02-27 21:22:39 +0000414
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000415 /* tcflow() constants */
416 {"TCOOFF", TCOOFF},
417 {"TCOON", TCOON},
418 {"TCIOFF", TCIOFF},
419 {"TCION", TCION},
Fred Drakedf48d142001-02-27 21:22:39 +0000420
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000421 /* struct termios.c_iflag constants */
422 {"IGNBRK", IGNBRK},
423 {"BRKINT", BRKINT},
424 {"IGNPAR", IGNPAR},
425 {"PARMRK", PARMRK},
426 {"INPCK", INPCK},
427 {"ISTRIP", ISTRIP},
428 {"INLCR", INLCR},
429 {"IGNCR", IGNCR},
430 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000431#ifdef IUCLC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000432 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000433#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000434 {"IXON", IXON},
435 {"IXANY", IXANY},
436 {"IXOFF", IXOFF},
Thomas Wouters2b305242001-06-15 12:05:44 +0000437#ifdef IMAXBEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000438 {"IMAXBEL", IMAXBEL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000439#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000440
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000441 /* struct termios.c_oflag constants */
442 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000443#ifdef OLCUC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000444 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000445#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000446#ifdef ONLCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000447 {"ONLCR", ONLCR},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000448#endif
Fred Draked85556c2001-03-03 18:08:52 +0000449#ifdef OCRNL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000450 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000451#endif
452#ifdef ONOCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000453 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000454#endif
455#ifdef ONLRET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000456 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000457#endif
458#ifdef OFILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000459 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000460#endif
461#ifdef OFDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000462 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000463#endif
464#ifdef NLDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000465 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000466#endif
467#ifdef CRDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000468 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000469#endif
470#ifdef TABDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000471 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000472#endif
473#ifdef BSDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000474 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000475#endif
476#ifdef VTDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000477 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000478#endif
479#ifdef FFDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000480 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000481#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000482
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000483 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000484#ifdef NL0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000485 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000486#endif
487#ifdef NL1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000488 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000489#endif
490#ifdef CR0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000491 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000492#endif
493#ifdef CR1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000494 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000495#endif
496#ifdef CR2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000497 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000498#endif
499#ifdef CR3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000500 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000501#endif
502#ifdef TAB0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000503 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000504#endif
505#ifdef TAB1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000506 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000507#endif
508#ifdef TAB2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000509 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000510#endif
511#ifdef TAB3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000512 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000513#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000514#ifdef XTABS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000515 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000516#endif
Fred Draked85556c2001-03-03 18:08:52 +0000517#ifdef BS0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000518 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000519#endif
520#ifdef BS1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000521 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000522#endif
523#ifdef VT0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000524 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000525#endif
526#ifdef VT1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000527 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000528#endif
529#ifdef FF0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000530 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000531#endif
532#ifdef FF1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000533 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000534#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000535
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000536 /* struct termios.c_cflag constants */
537 {"CSIZE", CSIZE},
538 {"CSTOPB", CSTOPB},
539 {"CREAD", CREAD},
540 {"PARENB", PARENB},
541 {"PARODD", PARODD},
542 {"HUPCL", HUPCL},
543 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000544#ifdef CIBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000545 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000546#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000547#ifdef CRTSCTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000548 {"CRTSCTS", (long)CRTSCTS},
Fred Drakededbebf2001-03-02 06:50:58 +0000549#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000550
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000551 /* struct termios.c_cflag-related values (character size) */
552 {"CS5", CS5},
553 {"CS6", CS6},
554 {"CS7", CS7},
555 {"CS8", CS8},
Fred Drakedf48d142001-02-27 21:22:39 +0000556
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000557 /* struct termios.c_lflag constants */
558 {"ISIG", ISIG},
559 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000560#ifdef XCASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000561 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000562#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000563 {"ECHO", ECHO},
564 {"ECHOE", ECHOE},
565 {"ECHOK", ECHOK},
566 {"ECHONL", ECHONL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000567#ifdef ECHOCTL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000568 {"ECHOCTL", ECHOCTL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000569#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000570#ifdef ECHOPRT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000571 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000572#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000573#ifdef ECHOKE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000574 {"ECHOKE", ECHOKE},
Thomas Wouters2b305242001-06-15 12:05:44 +0000575#endif
576#ifdef FLUSHO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000577 {"FLUSHO", FLUSHO},
Thomas Wouters2b305242001-06-15 12:05:44 +0000578#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000579 {"NOFLSH", NOFLSH},
580 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000581#ifdef PENDIN
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000582 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000583#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000584 {"IEXTEN", IEXTEN},
Fred Drakedf48d142001-02-27 21:22:39 +0000585
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000586 /* indexes into the control chars array returned by tcgetattr() */
587 {"VINTR", VINTR},
588 {"VQUIT", VQUIT},
589 {"VERASE", VERASE},
590 {"VKILL", VKILL},
591 {"VEOF", VEOF},
592 {"VTIME", VTIME},
593 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000594#ifdef VSWTC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000595 /* The #defines above ensure that if either is defined, both are,
596 * but both may be omitted by the system headers. ;-( */
597 {"VSWTC", VSWTC},
598 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000599#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000600 {"VSTART", VSTART},
601 {"VSTOP", VSTOP},
602 {"VSUSP", VSUSP},
603 {"VEOL", VEOL},
Fred Draked0b625d2001-05-22 15:44:15 +0000604#ifdef VREPRINT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000605 {"VREPRINT", VREPRINT},
Fred Drake87068f12001-05-11 16:14:17 +0000606#endif
Fred Draked0b625d2001-05-22 15:44:15 +0000607#ifdef VDISCARD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000608 {"VDISCARD", VDISCARD},
Fred Drake87068f12001-05-11 16:14:17 +0000609#endif
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000610#ifdef VWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000611 {"VWERASE", VWERASE},
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000612#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000613#ifdef VLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000614 {"VLNEXT", VLNEXT},
Thomas Wouters2b305242001-06-15 12:05:44 +0000615#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000616#ifdef VEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000617 {"VEOL2", VEOL2},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000618#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000619
Fred Drake55a00342001-03-26 17:14:02 +0000620
621#ifdef B460800
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000622 {"B460800", B460800},
Fred Drake55a00342001-03-26 17:14:02 +0000623#endif
Anthony Shaw7dc72b82020-01-04 23:56:31 +1100624#ifdef B500000
625 {"B500000", B500000},
626#endif
627#ifdef B576000
628 { "B576000", B576000},
629#endif
630#ifdef B921600
631 { "B921600", B921600},
632#endif
633#ifdef B1000000
634 { "B1000000", B1000000},
635#endif
636#ifdef B1152000
637 { "B1152000", B1152000},
638#endif
639#ifdef B1500000
640 { "B1500000", B1500000},
641#endif
642#ifdef B2000000
643 { "B2000000", B2000000},
644#endif
645#ifdef B2500000
646 { "B2500000", B2500000},
647#endif
648#ifdef B3000000
649 { "B3000000", B3000000},
650#endif
651#ifdef B3500000
652 { "B3500000", B3500000},
653#endif
654#ifdef B4000000
655 { "B4000000", B4000000},
656#endif
Fred Drake55a00342001-03-26 17:14:02 +0000657#ifdef CBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000658 {"CBAUD", CBAUD},
Fred Drake55a00342001-03-26 17:14:02 +0000659#endif
660#ifdef CDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000661 {"CDEL", CDEL},
Fred Drake55a00342001-03-26 17:14:02 +0000662#endif
663#ifdef CDSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000664 {"CDSUSP", CDSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000665#endif
666#ifdef CEOF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000667 {"CEOF", CEOF},
Fred Drake55a00342001-03-26 17:14:02 +0000668#endif
669#ifdef CEOL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000670 {"CEOL", CEOL},
Fred Drake55a00342001-03-26 17:14:02 +0000671#endif
672#ifdef CEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000673 {"CEOL2", CEOL2},
Fred Drake55a00342001-03-26 17:14:02 +0000674#endif
675#ifdef CEOT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000676 {"CEOT", CEOT},
Fred Drake55a00342001-03-26 17:14:02 +0000677#endif
678#ifdef CERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000679 {"CERASE", CERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000680#endif
681#ifdef CESC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000682 {"CESC", CESC},
Fred Drake55a00342001-03-26 17:14:02 +0000683#endif
684#ifdef CFLUSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000685 {"CFLUSH", CFLUSH},
Fred Drake55a00342001-03-26 17:14:02 +0000686#endif
687#ifdef CINTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000688 {"CINTR", CINTR},
Fred Drake55a00342001-03-26 17:14:02 +0000689#endif
690#ifdef CKILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000691 {"CKILL", CKILL},
Fred Drake55a00342001-03-26 17:14:02 +0000692#endif
693#ifdef CLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000694 {"CLNEXT", CLNEXT},
Fred Drake55a00342001-03-26 17:14:02 +0000695#endif
696#ifdef CNUL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000697 {"CNUL", CNUL},
Fred Drake55a00342001-03-26 17:14:02 +0000698#endif
699#ifdef COMMON
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000700 {"COMMON", COMMON},
Fred Drake55a00342001-03-26 17:14:02 +0000701#endif
702#ifdef CQUIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000703 {"CQUIT", CQUIT},
Fred Drake55a00342001-03-26 17:14:02 +0000704#endif
705#ifdef CRPRNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000706 {"CRPRNT", CRPRNT},
Fred Drake55a00342001-03-26 17:14:02 +0000707#endif
708#ifdef CSTART
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000709 {"CSTART", CSTART},
Fred Drake55a00342001-03-26 17:14:02 +0000710#endif
711#ifdef CSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000712 {"CSTOP", CSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000713#endif
714#ifdef CSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000715 {"CSUSP", CSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000716#endif
717#ifdef CSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000718 {"CSWTCH", CSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000719#endif
720#ifdef CWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000721 {"CWERASE", CWERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000722#endif
723#ifdef EXTA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000724 {"EXTA", EXTA},
Fred Drake55a00342001-03-26 17:14:02 +0000725#endif
726#ifdef EXTB
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000727 {"EXTB", EXTB},
Fred Drake55a00342001-03-26 17:14:02 +0000728#endif
729#ifdef FIOASYNC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000730 {"FIOASYNC", FIOASYNC},
Fred Drake55a00342001-03-26 17:14:02 +0000731#endif
732#ifdef FIOCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000733 {"FIOCLEX", FIOCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000734#endif
735#ifdef FIONBIO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000736 {"FIONBIO", FIONBIO},
Fred Drake55a00342001-03-26 17:14:02 +0000737#endif
738#ifdef FIONCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000739 {"FIONCLEX", FIONCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000740#endif
741#ifdef FIONREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000742 {"FIONREAD", FIONREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000743#endif
744#ifdef IBSHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000745 {"IBSHIFT", IBSHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000746#endif
747#ifdef INIT_C_CC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000748 {"INIT_C_CC", INIT_C_CC},
Fred Drake55a00342001-03-26 17:14:02 +0000749#endif
750#ifdef IOCSIZE_MASK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000751 {"IOCSIZE_MASK", IOCSIZE_MASK},
Fred Drake55a00342001-03-26 17:14:02 +0000752#endif
753#ifdef IOCSIZE_SHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000754 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000755#endif
756#ifdef NCC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000757 {"NCC", NCC},
Fred Drake55a00342001-03-26 17:14:02 +0000758#endif
759#ifdef NCCS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000760 {"NCCS", NCCS},
Fred Drake55a00342001-03-26 17:14:02 +0000761#endif
762#ifdef NSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000763 {"NSWTCH", NSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000764#endif
765#ifdef N_MOUSE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000766 {"N_MOUSE", N_MOUSE},
Fred Drake55a00342001-03-26 17:14:02 +0000767#endif
768#ifdef N_PPP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000769 {"N_PPP", N_PPP},
Fred Drake55a00342001-03-26 17:14:02 +0000770#endif
771#ifdef N_SLIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000772 {"N_SLIP", N_SLIP},
Fred Drake55a00342001-03-26 17:14:02 +0000773#endif
774#ifdef N_STRIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000775 {"N_STRIP", N_STRIP},
Fred Drake55a00342001-03-26 17:14:02 +0000776#endif
777#ifdef N_TTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000778 {"N_TTY", N_TTY},
Fred Drake55a00342001-03-26 17:14:02 +0000779#endif
780#ifdef TCFLSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000781 {"TCFLSH", TCFLSH},
Fred Drake55a00342001-03-26 17:14:02 +0000782#endif
783#ifdef TCGETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000784 {"TCGETA", TCGETA},
Fred Drake55a00342001-03-26 17:14:02 +0000785#endif
786#ifdef TCGETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000787 {"TCGETS", TCGETS},
Fred Drake55a00342001-03-26 17:14:02 +0000788#endif
789#ifdef TCSBRK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000790 {"TCSBRK", TCSBRK},
Fred Drake55a00342001-03-26 17:14:02 +0000791#endif
792#ifdef TCSBRKP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000793 {"TCSBRKP", TCSBRKP},
Fred Drake55a00342001-03-26 17:14:02 +0000794#endif
795#ifdef TCSETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000796 {"TCSETA", TCSETA},
Fred Drake55a00342001-03-26 17:14:02 +0000797#endif
798#ifdef TCSETAF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000799 {"TCSETAF", TCSETAF},
Fred Drake55a00342001-03-26 17:14:02 +0000800#endif
801#ifdef TCSETAW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000802 {"TCSETAW", TCSETAW},
Fred Drake55a00342001-03-26 17:14:02 +0000803#endif
804#ifdef TCSETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000805 {"TCSETS", TCSETS},
Fred Drake55a00342001-03-26 17:14:02 +0000806#endif
807#ifdef TCSETSF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000808 {"TCSETSF", TCSETSF},
Fred Drake55a00342001-03-26 17:14:02 +0000809#endif
810#ifdef TCSETSW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000811 {"TCSETSW", TCSETSW},
Fred Drake55a00342001-03-26 17:14:02 +0000812#endif
813#ifdef TCXONC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000814 {"TCXONC", TCXONC},
Fred Drake55a00342001-03-26 17:14:02 +0000815#endif
816#ifdef TIOCCONS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000817 {"TIOCCONS", TIOCCONS},
Fred Drake55a00342001-03-26 17:14:02 +0000818#endif
819#ifdef TIOCEXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000820 {"TIOCEXCL", TIOCEXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000821#endif
822#ifdef TIOCGETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000823 {"TIOCGETD", TIOCGETD},
Fred Drake55a00342001-03-26 17:14:02 +0000824#endif
825#ifdef TIOCGICOUNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000826 {"TIOCGICOUNT", TIOCGICOUNT},
Fred Drake55a00342001-03-26 17:14:02 +0000827#endif
828#ifdef TIOCGLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000829 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000830#endif
831#ifdef TIOCGPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000832 {"TIOCGPGRP", TIOCGPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000833#endif
834#ifdef TIOCGSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000835 {"TIOCGSERIAL", TIOCGSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000836#endif
837#ifdef TIOCGSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000838 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000839#endif
840#ifdef TIOCGWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000841 {"TIOCGWINSZ", TIOCGWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000842#endif
843#ifdef TIOCINQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000844 {"TIOCINQ", TIOCINQ},
Fred Drake55a00342001-03-26 17:14:02 +0000845#endif
846#ifdef TIOCLINUX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000847 {"TIOCLINUX", TIOCLINUX},
Fred Drake55a00342001-03-26 17:14:02 +0000848#endif
849#ifdef TIOCMBIC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000850 {"TIOCMBIC", TIOCMBIC},
Fred Drake55a00342001-03-26 17:14:02 +0000851#endif
852#ifdef TIOCMBIS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000853 {"TIOCMBIS", TIOCMBIS},
Fred Drake55a00342001-03-26 17:14:02 +0000854#endif
855#ifdef TIOCMGET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000856 {"TIOCMGET", TIOCMGET},
Fred Drake55a00342001-03-26 17:14:02 +0000857#endif
858#ifdef TIOCMIWAIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000859 {"TIOCMIWAIT", TIOCMIWAIT},
Fred Drake55a00342001-03-26 17:14:02 +0000860#endif
861#ifdef TIOCMSET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000862 {"TIOCMSET", TIOCMSET},
Fred Drake55a00342001-03-26 17:14:02 +0000863#endif
864#ifdef TIOCM_CAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000865 {"TIOCM_CAR", TIOCM_CAR},
Fred Drake55a00342001-03-26 17:14:02 +0000866#endif
867#ifdef TIOCM_CD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000868 {"TIOCM_CD", TIOCM_CD},
Fred Drake55a00342001-03-26 17:14:02 +0000869#endif
870#ifdef TIOCM_CTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000871 {"TIOCM_CTS", TIOCM_CTS},
Fred Drake55a00342001-03-26 17:14:02 +0000872#endif
873#ifdef TIOCM_DSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000874 {"TIOCM_DSR", TIOCM_DSR},
Fred Drake55a00342001-03-26 17:14:02 +0000875#endif
876#ifdef TIOCM_DTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000877 {"TIOCM_DTR", TIOCM_DTR},
Fred Drake55a00342001-03-26 17:14:02 +0000878#endif
879#ifdef TIOCM_LE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000880 {"TIOCM_LE", TIOCM_LE},
Fred Drake55a00342001-03-26 17:14:02 +0000881#endif
882#ifdef TIOCM_RI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000883 {"TIOCM_RI", TIOCM_RI},
Fred Drake55a00342001-03-26 17:14:02 +0000884#endif
885#ifdef TIOCM_RNG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000886 {"TIOCM_RNG", TIOCM_RNG},
Fred Drake55a00342001-03-26 17:14:02 +0000887#endif
888#ifdef TIOCM_RTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000889 {"TIOCM_RTS", TIOCM_RTS},
Fred Drake55a00342001-03-26 17:14:02 +0000890#endif
891#ifdef TIOCM_SR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000892 {"TIOCM_SR", TIOCM_SR},
Fred Drake55a00342001-03-26 17:14:02 +0000893#endif
894#ifdef TIOCM_ST
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000895 {"TIOCM_ST", TIOCM_ST},
Fred Drake55a00342001-03-26 17:14:02 +0000896#endif
897#ifdef TIOCNOTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000898 {"TIOCNOTTY", TIOCNOTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000899#endif
900#ifdef TIOCNXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000901 {"TIOCNXCL", TIOCNXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000902#endif
903#ifdef TIOCOUTQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000904 {"TIOCOUTQ", TIOCOUTQ},
Fred Drake55a00342001-03-26 17:14:02 +0000905#endif
906#ifdef TIOCPKT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000907 {"TIOCPKT", TIOCPKT},
Fred Drake55a00342001-03-26 17:14:02 +0000908#endif
909#ifdef TIOCPKT_DATA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000910 {"TIOCPKT_DATA", TIOCPKT_DATA},
Fred Drake55a00342001-03-26 17:14:02 +0000911#endif
912#ifdef TIOCPKT_DOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000913 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000914#endif
915#ifdef TIOCPKT_FLUSHREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000916 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000917#endif
918#ifdef TIOCPKT_FLUSHWRITE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000919 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
Fred Drake55a00342001-03-26 17:14:02 +0000920#endif
921#ifdef TIOCPKT_NOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000922 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000923#endif
924#ifdef TIOCPKT_START
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000925 {"TIOCPKT_START", TIOCPKT_START},
Fred Drake55a00342001-03-26 17:14:02 +0000926#endif
927#ifdef TIOCPKT_STOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000928 {"TIOCPKT_STOP", TIOCPKT_STOP},
Fred Drake55a00342001-03-26 17:14:02 +0000929#endif
930#ifdef TIOCSCTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000931 {"TIOCSCTTY", TIOCSCTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000932#endif
933#ifdef TIOCSERCONFIG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000934 {"TIOCSERCONFIG", TIOCSERCONFIG},
Fred Drake55a00342001-03-26 17:14:02 +0000935#endif
936#ifdef TIOCSERGETLSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000937 {"TIOCSERGETLSR", TIOCSERGETLSR},
Fred Drake55a00342001-03-26 17:14:02 +0000938#endif
939#ifdef TIOCSERGETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000940 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000941#endif
942#ifdef TIOCSERGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000943 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000944#endif
945#ifdef TIOCSERGWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000946 {"TIOCSERGWILD", TIOCSERGWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000947#endif
948#ifdef TIOCSERSETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000949 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000950#endif
951#ifdef TIOCSERSWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000952 {"TIOCSERSWILD", TIOCSERSWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000953#endif
954#ifdef TIOCSER_TEMT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000955 {"TIOCSER_TEMT", TIOCSER_TEMT},
Fred Drake55a00342001-03-26 17:14:02 +0000956#endif
957#ifdef TIOCSETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000958 {"TIOCSETD", TIOCSETD},
Fred Drake55a00342001-03-26 17:14:02 +0000959#endif
960#ifdef TIOCSLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000961 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000962#endif
963#ifdef TIOCSPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000964 {"TIOCSPGRP", TIOCSPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000965#endif
966#ifdef TIOCSSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000967 {"TIOCSSERIAL", TIOCSSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000968#endif
969#ifdef TIOCSSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000970 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000971#endif
972#ifdef TIOCSTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000973 {"TIOCSTI", TIOCSTI},
Fred Drake55a00342001-03-26 17:14:02 +0000974#endif
975#ifdef TIOCSWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000976 {"TIOCSWINSZ", TIOCSWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000977#endif
978#ifdef TIOCTTYGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000979 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000980#endif
981
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000982 /* sentinel */
983 {NULL, 0}
Fred Drakedf48d142001-02-27 21:22:39 +0000984};
985
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100986static int termiosmodule_traverse(PyObject *m, visitproc visit, void *arg) {
Hai Shif707d942020-03-16 21:15:01 +0800987 Py_VISIT(get_termios_state(m)->TermiosError);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100988 return 0;
989}
990
991static int termiosmodule_clear(PyObject *m) {
Hai Shif707d942020-03-16 21:15:01 +0800992 Py_CLEAR(get_termios_state(m)->TermiosError);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100993 return 0;
994}
995
996static void termiosmodule_free(void *m) {
997 termiosmodule_clear((PyObject *)m);
998}
Fred Drakedf48d142001-02-27 21:22:39 +0000999
Martin v. Löwis1a214512008-06-11 05:26:20 +00001000static struct PyModuleDef termiosmodule = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001001 PyModuleDef_HEAD_INIT,
1002 "termios",
1003 termios__doc__,
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001004 sizeof(termiosmodulestate),
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001005 termios_methods,
1006 NULL,
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001007 termiosmodule_traverse,
1008 termiosmodule_clear,
1009 termiosmodule_free,
Martin v. Löwis1a214512008-06-11 05:26:20 +00001010};
1011
Mark Hammondfe51c6d2002-08-02 02:27:13 +00001012PyMODINIT_FUNC
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00001013PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001014{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001015 PyObject *m;
1016 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001017
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001018 if ((m = PyState_FindModule(&termiosmodule)) != NULL) {
1019 Py_INCREF(m);
1020 return m;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001021 }
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001022
1023 if ((m = PyModule_Create(&termiosmodule)) == NULL) {
1024 return NULL;
1025 }
1026
Hai Shif707d942020-03-16 21:15:01 +08001027 termiosmodulestate *state = get_termios_state(m);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001028 state->TermiosError = PyErr_NewException("termios.error", NULL, NULL);
1029 if (state->TermiosError == NULL) {
1030 return NULL;
1031 }
1032 Py_INCREF(state->TermiosError);
1033 PyModule_AddObject(m, "error", state->TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +00001034
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001035 while (constant->name != NULL) {
1036 PyModule_AddIntConstant(m, constant->name, constant->value);
1037 ++constant;
1038 }
1039 return m;
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001040}