blob: 0fd93c06c720393cf8a5e231a8666ee2f7d2c658 [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;
45#define modulestate(o) ((termiosmodulestate *)PyModule_GetState(o))
46#define modulestate_global modulestate(PyState_FindModule(&termiosmodule))
Guido van Rossum9adae8e1994-09-12 10:41:22 +000047
Fred Drakeb638aaf2001-05-07 17:55:35 +000048static int fdconv(PyObject* obj, void* p)
49{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000050 int fd;
Fred Drakeb638aaf2001-05-07 17:55:35 +000051
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000052 fd = PyObject_AsFileDescriptor(obj);
53 if (fd >= 0) {
54 *(int*)p = fd;
55 return 1;
56 }
57 return 0;
Fred Drakeb638aaf2001-05-07 17:55:35 +000058}
Guido van Rossum9adae8e1994-09-12 10:41:22 +000059
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010060static struct PyModuleDef termiosmodule;
61
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000062PyDoc_STRVAR(termios_tcgetattr__doc__,
63"tcgetattr(fd) -> list_of_attrs\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +000064\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +000065Get the tty attributes for file descriptor fd, as follows:\n\
66[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
67of the tty special characters (each a string of length 1, except the items\n\
68with indices VMIN and VTIME, which are integers when these fields are\n\
69defined). The interpretation of the flags and the speeds as well as the\n\
70indexing in the cc array must be done using the symbolic constants defined\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000071in this module.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +000072
Guido van Rossum9adae8e1994-09-12 10:41:22 +000073static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +000074termios_tcgetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000075{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000076 int fd;
77 struct termios mode;
78 PyObject *cc;
79 speed_t ispeed, ospeed;
80 PyObject *v;
81 int i;
82 char ch;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000083
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000084 if (!PyArg_ParseTuple(args, "O&:tcgetattr",
85 fdconv, (void*)&fd))
86 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000087
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000088 if (tcgetattr(fd, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010089 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000090
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000091 ispeed = cfgetispeed(&mode);
92 ospeed = cfgetospeed(&mode);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000093
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000094 cc = PyList_New(NCCS);
95 if (cc == NULL)
96 return NULL;
97 for (i = 0; i < NCCS; i++) {
98 ch = (char)mode.c_cc[i];
99 v = PyBytes_FromStringAndSize(&ch, 1);
100 if (v == NULL)
101 goto err;
102 PyList_SetItem(cc, i, v);
103 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000104
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000105 /* Convert the MIN and TIME slots to integer. On some systems, the
106 MIN and TIME slots are the same as the EOF and EOL slots. So we
107 only do this in noncanonical input mode. */
108 if ((mode.c_lflag & ICANON) == 0) {
109 v = PyLong_FromLong((long)mode.c_cc[VMIN]);
110 if (v == NULL)
111 goto err;
112 PyList_SetItem(cc, VMIN, v);
113 v = PyLong_FromLong((long)mode.c_cc[VTIME]);
114 if (v == NULL)
115 goto err;
116 PyList_SetItem(cc, VTIME, v);
117 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000118
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000119 if (!(v = PyList_New(7)))
120 goto err;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000121
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000122 PyList_SetItem(v, 0, PyLong_FromLong((long)mode.c_iflag));
123 PyList_SetItem(v, 1, PyLong_FromLong((long)mode.c_oflag));
124 PyList_SetItem(v, 2, PyLong_FromLong((long)mode.c_cflag));
125 PyList_SetItem(v, 3, PyLong_FromLong((long)mode.c_lflag));
126 PyList_SetItem(v, 4, PyLong_FromLong((long)ispeed));
127 PyList_SetItem(v, 5, PyLong_FromLong((long)ospeed));
Zackery Spytz53835e92018-10-28 22:55:20 -0600128 if (PyErr_Occurred()) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000129 Py_DECREF(v);
130 goto err;
131 }
Zackery Spytz53835e92018-10-28 22:55:20 -0600132 PyList_SetItem(v, 6, cc);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000133 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000134 err:
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000135 Py_DECREF(cc);
136 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000137}
138
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000139PyDoc_STRVAR(termios_tcsetattr__doc__,
140"tcsetattr(fd, when, attributes) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000141\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000142Set the tty attributes for file descriptor fd.\n\
143The attributes to be set are taken from the attributes argument, which\n\
144is a list like the one returned by tcgetattr(). The when argument\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000145determines when the attributes are changed: termios.TCSANOW to\n\
146change immediately, termios.TCSADRAIN to change after transmitting all\n\
147queued output, or termios.TCSAFLUSH to change after transmitting all\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000148queued output and discarding all queued input. ");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000149
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000150static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000151termios_tcsetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000152{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000153 int fd, when;
154 struct termios mode;
155 speed_t ispeed, ospeed;
156 PyObject *term, *cc, *v;
157 int i;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000158
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000159 if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
160 fdconv, &fd, &when, &term))
161 return NULL;
162 if (!PyList_Check(term) || PyList_Size(term) != 7) {
163 PyErr_SetString(PyExc_TypeError,
164 "tcsetattr, arg 3: must be 7 element list");
165 return NULL;
166 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000167
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000168 /* Get the old mode, in case there are any hidden fields... */
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100169 termiosmodulestate *state = modulestate_global;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000170 if (tcgetattr(fd, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100171 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000172 mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
173 mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
174 mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
175 mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
176 ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
177 ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
178 cc = PyList_GetItem(term, 6);
179 if (PyErr_Occurred())
180 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000181
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000182 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
183 PyErr_Format(PyExc_TypeError,
184 "tcsetattr: attributes[6] must be %d element list",
185 NCCS);
186 return NULL;
187 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000188
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000189 for (i = 0; i < NCCS; i++) {
190 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000191
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000192 if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
193 mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
194 else if (PyLong_Check(v))
195 mode.c_cc[i] = (cc_t) PyLong_AsLong(v);
196 else {
197 PyErr_SetString(PyExc_TypeError,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000198 "tcsetattr: elements of attributes must be characters or integers");
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000199 return NULL;
200 }
201 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000202
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000203 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100204 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000205 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100206 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000207 if (tcsetattr(fd, when, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100208 return PyErr_SetFromErrno(state->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000209
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200210 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000211}
212
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000213PyDoc_STRVAR(termios_tcsendbreak__doc__,
214"tcsendbreak(fd, duration) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000215\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000216Send a break on file descriptor fd.\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000217A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000218has a system dependent meaning.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000219
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000220static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000221termios_tcsendbreak(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000222{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000223 int fd, duration;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000224
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000225 if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
226 fdconv, &fd, &duration))
227 return NULL;
228 if (tcsendbreak(fd, duration) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100229 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000230
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200231 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000232}
233
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000234PyDoc_STRVAR(termios_tcdrain__doc__,
235"tcdrain(fd) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000236\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000237Wait until all output written to file descriptor fd has been transmitted.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000238
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000239static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000240termios_tcdrain(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000241{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000242 int fd;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000243
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000244 if (!PyArg_ParseTuple(args, "O&:tcdrain",
245 fdconv, &fd))
246 return NULL;
247 if (tcdrain(fd) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100248 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000249
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200250 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000251}
252
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000253PyDoc_STRVAR(termios_tcflush__doc__,
254"tcflush(fd, queue) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000255\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000256Discard queued data on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000257The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
258queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000259both queues. ");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000260
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000261static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000262termios_tcflush(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000263{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000264 int fd, queue;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000265
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000266 if (!PyArg_ParseTuple(args, "O&i:tcflush",
267 fdconv, &fd, &queue))
268 return NULL;
269 if (tcflush(fd, queue) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100270 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000271
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200272 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000273}
274
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000275PyDoc_STRVAR(termios_tcflow__doc__,
276"tcflow(fd, action) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000277\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000278Suspend or resume input or output on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000279The action argument can be termios.TCOOFF to suspend output,\n\
280termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000281or termios.TCION to restart input.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000282
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000283static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000284termios_tcflow(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000285{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000286 int fd, action;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000287
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000288 if (!PyArg_ParseTuple(args, "O&i:tcflow",
289 fdconv, &fd, &action))
290 return NULL;
291 if (tcflow(fd, action) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100292 return PyErr_SetFromErrno(modulestate_global->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000293
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200294 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000295}
296
297static PyMethodDef termios_methods[] =
298{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000299 {"tcgetattr", termios_tcgetattr,
300 METH_VARARGS, termios_tcgetattr__doc__},
301 {"tcsetattr", termios_tcsetattr,
302 METH_VARARGS, termios_tcsetattr__doc__},
303 {"tcsendbreak", termios_tcsendbreak,
304 METH_VARARGS, termios_tcsendbreak__doc__},
305 {"tcdrain", termios_tcdrain,
306 METH_VARARGS, termios_tcdrain__doc__},
307 {"tcflush", termios_tcflush,
308 METH_VARARGS, termios_tcflush__doc__},
309 {"tcflow", termios_tcflow,
310 METH_VARARGS, termios_tcflow__doc__},
311 {NULL, NULL}
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000312};
313
Fred Drakedf48d142001-02-27 21:22:39 +0000314
Fred Drake9ef7fa82001-03-01 21:54:49 +0000315#if defined(VSWTCH) && !defined(VSWTC)
316#define VSWTC VSWTCH
317#endif
318
319#if defined(VSWTC) && !defined(VSWTCH)
320#define VSWTCH VSWTC
321#endif
322
Fred Drakedf48d142001-02-27 21:22:39 +0000323static struct constant {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000324 char *name;
325 long value;
Fred Drakedf48d142001-02-27 21:22:39 +0000326} termios_constants[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000327 /* cfgetospeed(), cfsetospeed() constants */
328 {"B0", B0},
329 {"B50", B50},
330 {"B75", B75},
331 {"B110", B110},
332 {"B134", B134},
333 {"B150", B150},
334 {"B200", B200},
335 {"B300", B300},
336 {"B600", B600},
337 {"B1200", B1200},
338 {"B1800", B1800},
339 {"B2400", B2400},
340 {"B4800", B4800},
341 {"B9600", B9600},
342 {"B19200", B19200},
343 {"B38400", B38400},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000344#ifdef B57600
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000345 {"B57600", B57600},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000346#endif
347#ifdef B115200
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000348 {"B115200", B115200},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000349#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000350#ifdef B230400
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000351 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000352#endif
Antoine Pitroua78f74c2010-11-20 20:03:08 +0000353#ifdef B460800
354 {"B460800", B460800},
355#endif
356#ifdef B500000
357 {"B500000", B500000},
358#endif
359#ifdef B576000
360 {"B576000", B576000},
361#endif
362#ifdef B921600
363 {"B921600", B921600},
364#endif
365#ifdef B1000000
366 {"B1000000", B1000000},
367#endif
368#ifdef B1152000
369 {"B1152000", B1152000},
370#endif
371#ifdef B1500000
372 {"B1500000", B1500000},
373#endif
374#ifdef B2000000
375 {"B2000000", B2000000},
376#endif
377#ifdef B2500000
378 {"B2500000", B2500000},
379#endif
380#ifdef B3000000
381 {"B3000000", B3000000},
382#endif
383#ifdef B3500000
384 {"B3500000", B3500000},
385#endif
386#ifdef B4000000
387 {"B4000000", B4000000},
388#endif
389
Fred Drake9ef7fa82001-03-01 21:54:49 +0000390#ifdef CBAUDEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000391 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000392#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000393
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000394 /* tcsetattr() constants */
395 {"TCSANOW", TCSANOW},
396 {"TCSADRAIN", TCSADRAIN},
397 {"TCSAFLUSH", TCSAFLUSH},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000398#ifdef TCSASOFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000399 {"TCSASOFT", TCSASOFT},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000400#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000401
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000402 /* tcflush() constants */
403 {"TCIFLUSH", TCIFLUSH},
404 {"TCOFLUSH", TCOFLUSH},
405 {"TCIOFLUSH", TCIOFLUSH},
Fred Drakedf48d142001-02-27 21:22:39 +0000406
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000407 /* tcflow() constants */
408 {"TCOOFF", TCOOFF},
409 {"TCOON", TCOON},
410 {"TCIOFF", TCIOFF},
411 {"TCION", TCION},
Fred Drakedf48d142001-02-27 21:22:39 +0000412
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000413 /* struct termios.c_iflag constants */
414 {"IGNBRK", IGNBRK},
415 {"BRKINT", BRKINT},
416 {"IGNPAR", IGNPAR},
417 {"PARMRK", PARMRK},
418 {"INPCK", INPCK},
419 {"ISTRIP", ISTRIP},
420 {"INLCR", INLCR},
421 {"IGNCR", IGNCR},
422 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000423#ifdef IUCLC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000424 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000425#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000426 {"IXON", IXON},
427 {"IXANY", IXANY},
428 {"IXOFF", IXOFF},
Thomas Wouters2b305242001-06-15 12:05:44 +0000429#ifdef IMAXBEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000430 {"IMAXBEL", IMAXBEL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000431#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000432
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000433 /* struct termios.c_oflag constants */
434 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000435#ifdef OLCUC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000436 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000437#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000438#ifdef ONLCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000439 {"ONLCR", ONLCR},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000440#endif
Fred Draked85556c2001-03-03 18:08:52 +0000441#ifdef OCRNL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000442 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000443#endif
444#ifdef ONOCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000445 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000446#endif
447#ifdef ONLRET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000448 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000449#endif
450#ifdef OFILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000451 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000452#endif
453#ifdef OFDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000454 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000455#endif
456#ifdef NLDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000457 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000458#endif
459#ifdef CRDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000460 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000461#endif
462#ifdef TABDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000463 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000464#endif
465#ifdef BSDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000466 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000467#endif
468#ifdef VTDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000469 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000470#endif
471#ifdef FFDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000472 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000473#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000474
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000475 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000476#ifdef NL0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000477 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000478#endif
479#ifdef NL1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000480 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000481#endif
482#ifdef CR0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000483 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000484#endif
485#ifdef CR1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000486 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000487#endif
488#ifdef CR2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000489 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000490#endif
491#ifdef CR3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000492 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000493#endif
494#ifdef TAB0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000495 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000496#endif
497#ifdef TAB1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000498 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000499#endif
500#ifdef TAB2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000501 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000502#endif
503#ifdef TAB3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000504 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000505#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000506#ifdef XTABS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000507 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000508#endif
Fred Draked85556c2001-03-03 18:08:52 +0000509#ifdef BS0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000510 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000511#endif
512#ifdef BS1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000513 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000514#endif
515#ifdef VT0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000516 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000517#endif
518#ifdef VT1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000519 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000520#endif
521#ifdef FF0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000522 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000523#endif
524#ifdef FF1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000525 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000526#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000527
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000528 /* struct termios.c_cflag constants */
529 {"CSIZE", CSIZE},
530 {"CSTOPB", CSTOPB},
531 {"CREAD", CREAD},
532 {"PARENB", PARENB},
533 {"PARODD", PARODD},
534 {"HUPCL", HUPCL},
535 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000536#ifdef CIBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000537 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000538#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000539#ifdef CRTSCTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000540 {"CRTSCTS", (long)CRTSCTS},
Fred Drakededbebf2001-03-02 06:50:58 +0000541#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000542
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000543 /* struct termios.c_cflag-related values (character size) */
544 {"CS5", CS5},
545 {"CS6", CS6},
546 {"CS7", CS7},
547 {"CS8", CS8},
Fred Drakedf48d142001-02-27 21:22:39 +0000548
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000549 /* struct termios.c_lflag constants */
550 {"ISIG", ISIG},
551 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000552#ifdef XCASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000553 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000554#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000555 {"ECHO", ECHO},
556 {"ECHOE", ECHOE},
557 {"ECHOK", ECHOK},
558 {"ECHONL", ECHONL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000559#ifdef ECHOCTL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000560 {"ECHOCTL", ECHOCTL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000561#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000562#ifdef ECHOPRT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000563 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000564#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000565#ifdef ECHOKE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000566 {"ECHOKE", ECHOKE},
Thomas Wouters2b305242001-06-15 12:05:44 +0000567#endif
568#ifdef FLUSHO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000569 {"FLUSHO", FLUSHO},
Thomas Wouters2b305242001-06-15 12:05:44 +0000570#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000571 {"NOFLSH", NOFLSH},
572 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000573#ifdef PENDIN
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000574 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000575#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000576 {"IEXTEN", IEXTEN},
Fred Drakedf48d142001-02-27 21:22:39 +0000577
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000578 /* indexes into the control chars array returned by tcgetattr() */
579 {"VINTR", VINTR},
580 {"VQUIT", VQUIT},
581 {"VERASE", VERASE},
582 {"VKILL", VKILL},
583 {"VEOF", VEOF},
584 {"VTIME", VTIME},
585 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000586#ifdef VSWTC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000587 /* The #defines above ensure that if either is defined, both are,
588 * but both may be omitted by the system headers. ;-( */
589 {"VSWTC", VSWTC},
590 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000591#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000592 {"VSTART", VSTART},
593 {"VSTOP", VSTOP},
594 {"VSUSP", VSUSP},
595 {"VEOL", VEOL},
Fred Draked0b625d2001-05-22 15:44:15 +0000596#ifdef VREPRINT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000597 {"VREPRINT", VREPRINT},
Fred Drake87068f12001-05-11 16:14:17 +0000598#endif
Fred Draked0b625d2001-05-22 15:44:15 +0000599#ifdef VDISCARD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000600 {"VDISCARD", VDISCARD},
Fred Drake87068f12001-05-11 16:14:17 +0000601#endif
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000602#ifdef VWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000603 {"VWERASE", VWERASE},
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000604#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000605#ifdef VLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000606 {"VLNEXT", VLNEXT},
Thomas Wouters2b305242001-06-15 12:05:44 +0000607#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000608#ifdef VEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000609 {"VEOL2", VEOL2},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000610#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000611
Fred Drake55a00342001-03-26 17:14:02 +0000612
613#ifdef B460800
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000614 {"B460800", B460800},
Fred Drake55a00342001-03-26 17:14:02 +0000615#endif
Anthony Shaw7dc72b82020-01-04 23:56:31 +1100616#ifdef B500000
617 {"B500000", B500000},
618#endif
619#ifdef B576000
620 { "B576000", B576000},
621#endif
622#ifdef B921600
623 { "B921600", B921600},
624#endif
625#ifdef B1000000
626 { "B1000000", B1000000},
627#endif
628#ifdef B1152000
629 { "B1152000", B1152000},
630#endif
631#ifdef B1500000
632 { "B1500000", B1500000},
633#endif
634#ifdef B2000000
635 { "B2000000", B2000000},
636#endif
637#ifdef B2500000
638 { "B2500000", B2500000},
639#endif
640#ifdef B3000000
641 { "B3000000", B3000000},
642#endif
643#ifdef B3500000
644 { "B3500000", B3500000},
645#endif
646#ifdef B4000000
647 { "B4000000", B4000000},
648#endif
Fred Drake55a00342001-03-26 17:14:02 +0000649#ifdef CBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000650 {"CBAUD", CBAUD},
Fred Drake55a00342001-03-26 17:14:02 +0000651#endif
652#ifdef CDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000653 {"CDEL", CDEL},
Fred Drake55a00342001-03-26 17:14:02 +0000654#endif
655#ifdef CDSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000656 {"CDSUSP", CDSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000657#endif
658#ifdef CEOF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000659 {"CEOF", CEOF},
Fred Drake55a00342001-03-26 17:14:02 +0000660#endif
661#ifdef CEOL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000662 {"CEOL", CEOL},
Fred Drake55a00342001-03-26 17:14:02 +0000663#endif
664#ifdef CEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000665 {"CEOL2", CEOL2},
Fred Drake55a00342001-03-26 17:14:02 +0000666#endif
667#ifdef CEOT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000668 {"CEOT", CEOT},
Fred Drake55a00342001-03-26 17:14:02 +0000669#endif
670#ifdef CERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000671 {"CERASE", CERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000672#endif
673#ifdef CESC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000674 {"CESC", CESC},
Fred Drake55a00342001-03-26 17:14:02 +0000675#endif
676#ifdef CFLUSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000677 {"CFLUSH", CFLUSH},
Fred Drake55a00342001-03-26 17:14:02 +0000678#endif
679#ifdef CINTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000680 {"CINTR", CINTR},
Fred Drake55a00342001-03-26 17:14:02 +0000681#endif
682#ifdef CKILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000683 {"CKILL", CKILL},
Fred Drake55a00342001-03-26 17:14:02 +0000684#endif
685#ifdef CLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000686 {"CLNEXT", CLNEXT},
Fred Drake55a00342001-03-26 17:14:02 +0000687#endif
688#ifdef CNUL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000689 {"CNUL", CNUL},
Fred Drake55a00342001-03-26 17:14:02 +0000690#endif
691#ifdef COMMON
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000692 {"COMMON", COMMON},
Fred Drake55a00342001-03-26 17:14:02 +0000693#endif
694#ifdef CQUIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000695 {"CQUIT", CQUIT},
Fred Drake55a00342001-03-26 17:14:02 +0000696#endif
697#ifdef CRPRNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000698 {"CRPRNT", CRPRNT},
Fred Drake55a00342001-03-26 17:14:02 +0000699#endif
700#ifdef CSTART
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000701 {"CSTART", CSTART},
Fred Drake55a00342001-03-26 17:14:02 +0000702#endif
703#ifdef CSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000704 {"CSTOP", CSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000705#endif
706#ifdef CSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000707 {"CSUSP", CSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000708#endif
709#ifdef CSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000710 {"CSWTCH", CSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000711#endif
712#ifdef CWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000713 {"CWERASE", CWERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000714#endif
715#ifdef EXTA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000716 {"EXTA", EXTA},
Fred Drake55a00342001-03-26 17:14:02 +0000717#endif
718#ifdef EXTB
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000719 {"EXTB", EXTB},
Fred Drake55a00342001-03-26 17:14:02 +0000720#endif
721#ifdef FIOASYNC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000722 {"FIOASYNC", FIOASYNC},
Fred Drake55a00342001-03-26 17:14:02 +0000723#endif
724#ifdef FIOCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000725 {"FIOCLEX", FIOCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000726#endif
727#ifdef FIONBIO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000728 {"FIONBIO", FIONBIO},
Fred Drake55a00342001-03-26 17:14:02 +0000729#endif
730#ifdef FIONCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000731 {"FIONCLEX", FIONCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000732#endif
733#ifdef FIONREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000734 {"FIONREAD", FIONREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000735#endif
736#ifdef IBSHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000737 {"IBSHIFT", IBSHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000738#endif
739#ifdef INIT_C_CC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000740 {"INIT_C_CC", INIT_C_CC},
Fred Drake55a00342001-03-26 17:14:02 +0000741#endif
742#ifdef IOCSIZE_MASK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000743 {"IOCSIZE_MASK", IOCSIZE_MASK},
Fred Drake55a00342001-03-26 17:14:02 +0000744#endif
745#ifdef IOCSIZE_SHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000746 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000747#endif
748#ifdef NCC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000749 {"NCC", NCC},
Fred Drake55a00342001-03-26 17:14:02 +0000750#endif
751#ifdef NCCS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000752 {"NCCS", NCCS},
Fred Drake55a00342001-03-26 17:14:02 +0000753#endif
754#ifdef NSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000755 {"NSWTCH", NSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000756#endif
757#ifdef N_MOUSE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000758 {"N_MOUSE", N_MOUSE},
Fred Drake55a00342001-03-26 17:14:02 +0000759#endif
760#ifdef N_PPP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000761 {"N_PPP", N_PPP},
Fred Drake55a00342001-03-26 17:14:02 +0000762#endif
763#ifdef N_SLIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000764 {"N_SLIP", N_SLIP},
Fred Drake55a00342001-03-26 17:14:02 +0000765#endif
766#ifdef N_STRIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000767 {"N_STRIP", N_STRIP},
Fred Drake55a00342001-03-26 17:14:02 +0000768#endif
769#ifdef N_TTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000770 {"N_TTY", N_TTY},
Fred Drake55a00342001-03-26 17:14:02 +0000771#endif
772#ifdef TCFLSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000773 {"TCFLSH", TCFLSH},
Fred Drake55a00342001-03-26 17:14:02 +0000774#endif
775#ifdef TCGETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000776 {"TCGETA", TCGETA},
Fred Drake55a00342001-03-26 17:14:02 +0000777#endif
778#ifdef TCGETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000779 {"TCGETS", TCGETS},
Fred Drake55a00342001-03-26 17:14:02 +0000780#endif
781#ifdef TCSBRK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000782 {"TCSBRK", TCSBRK},
Fred Drake55a00342001-03-26 17:14:02 +0000783#endif
784#ifdef TCSBRKP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000785 {"TCSBRKP", TCSBRKP},
Fred Drake55a00342001-03-26 17:14:02 +0000786#endif
787#ifdef TCSETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000788 {"TCSETA", TCSETA},
Fred Drake55a00342001-03-26 17:14:02 +0000789#endif
790#ifdef TCSETAF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000791 {"TCSETAF", TCSETAF},
Fred Drake55a00342001-03-26 17:14:02 +0000792#endif
793#ifdef TCSETAW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000794 {"TCSETAW", TCSETAW},
Fred Drake55a00342001-03-26 17:14:02 +0000795#endif
796#ifdef TCSETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000797 {"TCSETS", TCSETS},
Fred Drake55a00342001-03-26 17:14:02 +0000798#endif
799#ifdef TCSETSF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000800 {"TCSETSF", TCSETSF},
Fred Drake55a00342001-03-26 17:14:02 +0000801#endif
802#ifdef TCSETSW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000803 {"TCSETSW", TCSETSW},
Fred Drake55a00342001-03-26 17:14:02 +0000804#endif
805#ifdef TCXONC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000806 {"TCXONC", TCXONC},
Fred Drake55a00342001-03-26 17:14:02 +0000807#endif
808#ifdef TIOCCONS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000809 {"TIOCCONS", TIOCCONS},
Fred Drake55a00342001-03-26 17:14:02 +0000810#endif
811#ifdef TIOCEXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000812 {"TIOCEXCL", TIOCEXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000813#endif
814#ifdef TIOCGETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000815 {"TIOCGETD", TIOCGETD},
Fred Drake55a00342001-03-26 17:14:02 +0000816#endif
817#ifdef TIOCGICOUNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000818 {"TIOCGICOUNT", TIOCGICOUNT},
Fred Drake55a00342001-03-26 17:14:02 +0000819#endif
820#ifdef TIOCGLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000821 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000822#endif
823#ifdef TIOCGPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000824 {"TIOCGPGRP", TIOCGPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000825#endif
826#ifdef TIOCGSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000827 {"TIOCGSERIAL", TIOCGSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000828#endif
829#ifdef TIOCGSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000830 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000831#endif
832#ifdef TIOCGWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000833 {"TIOCGWINSZ", TIOCGWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000834#endif
835#ifdef TIOCINQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000836 {"TIOCINQ", TIOCINQ},
Fred Drake55a00342001-03-26 17:14:02 +0000837#endif
838#ifdef TIOCLINUX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000839 {"TIOCLINUX", TIOCLINUX},
Fred Drake55a00342001-03-26 17:14:02 +0000840#endif
841#ifdef TIOCMBIC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000842 {"TIOCMBIC", TIOCMBIC},
Fred Drake55a00342001-03-26 17:14:02 +0000843#endif
844#ifdef TIOCMBIS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000845 {"TIOCMBIS", TIOCMBIS},
Fred Drake55a00342001-03-26 17:14:02 +0000846#endif
847#ifdef TIOCMGET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000848 {"TIOCMGET", TIOCMGET},
Fred Drake55a00342001-03-26 17:14:02 +0000849#endif
850#ifdef TIOCMIWAIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000851 {"TIOCMIWAIT", TIOCMIWAIT},
Fred Drake55a00342001-03-26 17:14:02 +0000852#endif
853#ifdef TIOCMSET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000854 {"TIOCMSET", TIOCMSET},
Fred Drake55a00342001-03-26 17:14:02 +0000855#endif
856#ifdef TIOCM_CAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000857 {"TIOCM_CAR", TIOCM_CAR},
Fred Drake55a00342001-03-26 17:14:02 +0000858#endif
859#ifdef TIOCM_CD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000860 {"TIOCM_CD", TIOCM_CD},
Fred Drake55a00342001-03-26 17:14:02 +0000861#endif
862#ifdef TIOCM_CTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000863 {"TIOCM_CTS", TIOCM_CTS},
Fred Drake55a00342001-03-26 17:14:02 +0000864#endif
865#ifdef TIOCM_DSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000866 {"TIOCM_DSR", TIOCM_DSR},
Fred Drake55a00342001-03-26 17:14:02 +0000867#endif
868#ifdef TIOCM_DTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000869 {"TIOCM_DTR", TIOCM_DTR},
Fred Drake55a00342001-03-26 17:14:02 +0000870#endif
871#ifdef TIOCM_LE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000872 {"TIOCM_LE", TIOCM_LE},
Fred Drake55a00342001-03-26 17:14:02 +0000873#endif
874#ifdef TIOCM_RI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000875 {"TIOCM_RI", TIOCM_RI},
Fred Drake55a00342001-03-26 17:14:02 +0000876#endif
877#ifdef TIOCM_RNG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000878 {"TIOCM_RNG", TIOCM_RNG},
Fred Drake55a00342001-03-26 17:14:02 +0000879#endif
880#ifdef TIOCM_RTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000881 {"TIOCM_RTS", TIOCM_RTS},
Fred Drake55a00342001-03-26 17:14:02 +0000882#endif
883#ifdef TIOCM_SR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000884 {"TIOCM_SR", TIOCM_SR},
Fred Drake55a00342001-03-26 17:14:02 +0000885#endif
886#ifdef TIOCM_ST
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000887 {"TIOCM_ST", TIOCM_ST},
Fred Drake55a00342001-03-26 17:14:02 +0000888#endif
889#ifdef TIOCNOTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000890 {"TIOCNOTTY", TIOCNOTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000891#endif
892#ifdef TIOCNXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000893 {"TIOCNXCL", TIOCNXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000894#endif
895#ifdef TIOCOUTQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000896 {"TIOCOUTQ", TIOCOUTQ},
Fred Drake55a00342001-03-26 17:14:02 +0000897#endif
898#ifdef TIOCPKT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000899 {"TIOCPKT", TIOCPKT},
Fred Drake55a00342001-03-26 17:14:02 +0000900#endif
901#ifdef TIOCPKT_DATA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000902 {"TIOCPKT_DATA", TIOCPKT_DATA},
Fred Drake55a00342001-03-26 17:14:02 +0000903#endif
904#ifdef TIOCPKT_DOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000905 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000906#endif
907#ifdef TIOCPKT_FLUSHREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000908 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000909#endif
910#ifdef TIOCPKT_FLUSHWRITE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000911 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
Fred Drake55a00342001-03-26 17:14:02 +0000912#endif
913#ifdef TIOCPKT_NOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000914 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000915#endif
916#ifdef TIOCPKT_START
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000917 {"TIOCPKT_START", TIOCPKT_START},
Fred Drake55a00342001-03-26 17:14:02 +0000918#endif
919#ifdef TIOCPKT_STOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000920 {"TIOCPKT_STOP", TIOCPKT_STOP},
Fred Drake55a00342001-03-26 17:14:02 +0000921#endif
922#ifdef TIOCSCTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000923 {"TIOCSCTTY", TIOCSCTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000924#endif
925#ifdef TIOCSERCONFIG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000926 {"TIOCSERCONFIG", TIOCSERCONFIG},
Fred Drake55a00342001-03-26 17:14:02 +0000927#endif
928#ifdef TIOCSERGETLSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000929 {"TIOCSERGETLSR", TIOCSERGETLSR},
Fred Drake55a00342001-03-26 17:14:02 +0000930#endif
931#ifdef TIOCSERGETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000932 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000933#endif
934#ifdef TIOCSERGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000935 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000936#endif
937#ifdef TIOCSERGWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000938 {"TIOCSERGWILD", TIOCSERGWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000939#endif
940#ifdef TIOCSERSETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000941 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000942#endif
943#ifdef TIOCSERSWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000944 {"TIOCSERSWILD", TIOCSERSWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000945#endif
946#ifdef TIOCSER_TEMT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000947 {"TIOCSER_TEMT", TIOCSER_TEMT},
Fred Drake55a00342001-03-26 17:14:02 +0000948#endif
949#ifdef TIOCSETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000950 {"TIOCSETD", TIOCSETD},
Fred Drake55a00342001-03-26 17:14:02 +0000951#endif
952#ifdef TIOCSLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000953 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000954#endif
955#ifdef TIOCSPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000956 {"TIOCSPGRP", TIOCSPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000957#endif
958#ifdef TIOCSSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000959 {"TIOCSSERIAL", TIOCSSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000960#endif
961#ifdef TIOCSSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000962 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000963#endif
964#ifdef TIOCSTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000965 {"TIOCSTI", TIOCSTI},
Fred Drake55a00342001-03-26 17:14:02 +0000966#endif
967#ifdef TIOCSWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000968 {"TIOCSWINSZ", TIOCSWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000969#endif
970#ifdef TIOCTTYGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000971 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000972#endif
973
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000974 /* sentinel */
975 {NULL, 0}
Fred Drakedf48d142001-02-27 21:22:39 +0000976};
977
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100978static int termiosmodule_traverse(PyObject *m, visitproc visit, void *arg) {
979 Py_VISIT(modulestate(m)->TermiosError);
980 return 0;
981}
982
983static int termiosmodule_clear(PyObject *m) {
984 Py_CLEAR(modulestate(m)->TermiosError);
985 return 0;
986}
987
988static void termiosmodule_free(void *m) {
989 termiosmodule_clear((PyObject *)m);
990}
Fred Drakedf48d142001-02-27 21:22:39 +0000991
Martin v. Löwis1a214512008-06-11 05:26:20 +0000992static struct PyModuleDef termiosmodule = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000993 PyModuleDef_HEAD_INIT,
994 "termios",
995 termios__doc__,
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100996 sizeof(termiosmodulestate),
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000997 termios_methods,
998 NULL,
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100999 termiosmodule_traverse,
1000 termiosmodule_clear,
1001 termiosmodule_free,
Martin v. Löwis1a214512008-06-11 05:26:20 +00001002};
1003
Mark Hammondfe51c6d2002-08-02 02:27:13 +00001004PyMODINIT_FUNC
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00001005PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001006{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001007 PyObject *m;
1008 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001009
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001010 if ((m = PyState_FindModule(&termiosmodule)) != NULL) {
1011 Py_INCREF(m);
1012 return m;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001013 }
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001014
1015 if ((m = PyModule_Create(&termiosmodule)) == NULL) {
1016 return NULL;
1017 }
1018
1019 termiosmodulestate *state = PyModule_GetState(m);
1020 state->TermiosError = PyErr_NewException("termios.error", NULL, NULL);
1021 if (state->TermiosError == NULL) {
1022 return NULL;
1023 }
1024 Py_INCREF(state->TermiosError);
1025 PyModule_AddObject(m, "error", state->TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +00001026
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001027 while (constant->name != NULL) {
1028 PyModule_AddIntConstant(m, constant->name, constant->value);
1029 ++constant;
1030 }
1031 return m;
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001032}