blob: 79b60ffaaba4a32aada867fe7a796f232f5acdbe [file] [log] [blame]
Soumendra Ganguly97003462020-08-16 10:51:00 -05001/* termios.c -- POSIX terminal I/O module implementation. */
Guido van Rossum9adae8e1994-09-12 10:41:22 +00002
Guido van Rossumca6954a1999-01-14 19:31:42 +00003#include "Python.h"
Guido van Rossum9adae8e1994-09-12 10:41:22 +00004
Martin v. Löwisbe4fea62003-10-31 13:01:24 +00005/* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE
6 is defined, so we define it here. */
7#if defined(__sgi)
8#define CTRL(c) ((c)&037)
9#endif
10
jceaf0a95f22018-01-28 14:00:48 +010011#if defined(__sun)
12/* We could do better. Check issue-32660 */
13#include <sys/filio.h>
14#include <sys/sockio.h>
15#endif
16
Guido van Rossum9adae8e1994-09-12 10:41:22 +000017#include <termios.h>
Fred Drake9b3bc492001-04-04 21:19:26 +000018#include <sys/ioctl.h>
Guido van Rossum1aca4d81998-03-03 22:10:18 +000019
Fred Drake87068f12001-05-11 16:14:17 +000020/* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
Min ho Kim39d87b52019-08-31 06:21:19 +100021 * MDTR, MRI, and MRTS (apparently used internally by some things
Fred Drake87068f12001-05-11 16:14:17 +000022 * defined as macros; these are not used here directly).
23 */
24#ifdef HAVE_SYS_MODEM_H
25#include <sys/modem.h>
26#endif
Neal Norwitz82251032003-05-23 14:35:24 +000027/* HP-UX requires that this be included to pick up TIOCGPGRP and friends */
28#ifdef HAVE_SYS_BSDTTY_H
29#include <sys/bsdtty.h>
30#endif
Fred Drake87068f12001-05-11 16:14:17 +000031
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
Dino Viehlandbd0c7a12019-09-10 11:33:30 +010054static struct PyModuleDef termiosmodule;
55
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000056PyDoc_STRVAR(termios_tcgetattr__doc__,
57"tcgetattr(fd) -> list_of_attrs\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +000058\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +000059Get the tty attributes for file descriptor fd, as follows:\n\
60[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
61of the tty special characters (each a string of length 1, except the items\n\
62with indices VMIN and VTIME, which are integers when these fields are\n\
63defined). The interpretation of the flags and the speeds as well as the\n\
64indexing in the cc array must be done using the symbolic constants defined\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000065in this module.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +000066
Guido van Rossum9adae8e1994-09-12 10:41:22 +000067static PyObject *
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -050068termios_tcgetattr(PyObject *module, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000069{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000070 int fd;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -050071 if (!PyArg_ParseTuple(args, "O&:tcgetattr",
Serhiy Storchaka9975cc52020-10-09 23:00:45 +030072 _PyLong_FileDescriptor_Converter, (void*)&fd)) {
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -050073 return NULL;
74 }
75
76 termiosmodulestate *state = PyModule_GetState(module);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000077 struct termios mode;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -050078 if (tcgetattr(fd, &mode) == -1) {
79 return PyErr_SetFromErrno(state->TermiosError);
80 }
81
82 speed_t ispeed = cfgetispeed(&mode);
83 speed_t ospeed = cfgetospeed(&mode);
84
85 PyObject *cc = PyList_New(NCCS);
86 if (cc == NULL) {
87 return NULL;
88 }
89
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000090 PyObject *v;
91 int i;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000092 for (i = 0; i < NCCS; i++) {
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -050093 char ch = (char)mode.c_cc[i];
Antoine Pitrouf95a1b32010-05-09 15:52:27 +000094 v = PyBytes_FromStringAndSize(&ch, 1);
95 if (v == NULL)
96 goto err;
97 PyList_SetItem(cc, i, v);
98 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +000099
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000100 /* Convert the MIN and TIME slots to integer. On some systems, the
101 MIN and TIME slots are the same as the EOF and EOL slots. So we
102 only do this in noncanonical input mode. */
103 if ((mode.c_lflag & ICANON) == 0) {
104 v = PyLong_FromLong((long)mode.c_cc[VMIN]);
105 if (v == NULL)
106 goto err;
107 PyList_SetItem(cc, VMIN, v);
108 v = PyLong_FromLong((long)mode.c_cc[VTIME]);
109 if (v == NULL)
110 goto err;
111 PyList_SetItem(cc, VTIME, v);
112 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000113
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000114 if (!(v = PyList_New(7)))
115 goto err;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000116
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000117 PyList_SetItem(v, 0, PyLong_FromLong((long)mode.c_iflag));
118 PyList_SetItem(v, 1, PyLong_FromLong((long)mode.c_oflag));
119 PyList_SetItem(v, 2, PyLong_FromLong((long)mode.c_cflag));
120 PyList_SetItem(v, 3, PyLong_FromLong((long)mode.c_lflag));
121 PyList_SetItem(v, 4, PyLong_FromLong((long)ispeed));
122 PyList_SetItem(v, 5, PyLong_FromLong((long)ospeed));
Zackery Spytz53835e92018-10-28 22:55:20 -0600123 if (PyErr_Occurred()) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000124 Py_DECREF(v);
125 goto err;
126 }
Zackery Spytz53835e92018-10-28 22:55:20 -0600127 PyList_SetItem(v, 6, cc);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000128 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000129 err:
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000130 Py_DECREF(cc);
131 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000132}
133
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000134PyDoc_STRVAR(termios_tcsetattr__doc__,
135"tcsetattr(fd, when, attributes) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000136\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000137Set the tty attributes for file descriptor fd.\n\
138The attributes to be set are taken from the attributes argument, which\n\
139is a list like the one returned by tcgetattr(). The when argument\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000140determines when the attributes are changed: termios.TCSANOW to\n\
141change immediately, termios.TCSADRAIN to change after transmitting all\n\
142queued output, or termios.TCSAFLUSH to change after transmitting all\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000143queued output and discarding all queued input. ");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000144
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000145static PyObject *
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500146termios_tcsetattr(PyObject *module, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000147{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000148 int fd, when;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500149 PyObject *term;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000150 if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
Serhiy Storchaka9975cc52020-10-09 23:00:45 +0300151 _PyLong_FileDescriptor_Converter, &fd, &when, &term)) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000152 return NULL;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500153 }
154
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000155 if (!PyList_Check(term) || PyList_Size(term) != 7) {
156 PyErr_SetString(PyExc_TypeError,
157 "tcsetattr, arg 3: must be 7 element list");
158 return NULL;
159 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000160
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000161 /* Get the old mode, in case there are any hidden fields... */
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500162 termiosmodulestate *state = PyModule_GetState(module);
163 struct termios mode;
164 if (tcgetattr(fd, &mode) == -1) {
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100165 return PyErr_SetFromErrno(state->TermiosError);
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500166 }
167
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000168 mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
169 mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
170 mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
171 mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500172 speed_t ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
173 speed_t ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
174 PyObject *cc = PyList_GetItem(term, 6);
175 if (PyErr_Occurred()) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000176 return NULL;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500177 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000178
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000179 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
180 PyErr_Format(PyExc_TypeError,
181 "tcsetattr: attributes[6] must be %d element list",
182 NCCS);
183 return NULL;
184 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000185
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500186 int i;
187 PyObject *v;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000188 for (i = 0; i < NCCS; i++) {
189 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000190
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000191 if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
192 mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
193 else if (PyLong_Check(v))
194 mode.c_cc[i] = (cc_t) PyLong_AsLong(v);
195 else {
196 PyErr_SetString(PyExc_TypeError,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000197 "tcsetattr: elements of attributes must be characters or integers");
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000198 return NULL;
199 }
200 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000201
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000202 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100203 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000204 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100205 return PyErr_SetFromErrno(state->TermiosError);
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000206 if (tcsetattr(fd, when, &mode) == -1)
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100207 return PyErr_SetFromErrno(state->TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000208
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200209 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000210}
211
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000212PyDoc_STRVAR(termios_tcsendbreak__doc__,
213"tcsendbreak(fd, duration) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000214\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000215Send a break on file descriptor fd.\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000216A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000217has a system dependent meaning.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000218
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000219static PyObject *
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500220termios_tcsendbreak(PyObject *module, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000221{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000222 int fd, duration;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000223 if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
Serhiy Storchaka9975cc52020-10-09 23:00:45 +0300224 _PyLong_FileDescriptor_Converter, &fd, &duration)) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000225 return NULL;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500226 }
227
228 termiosmodulestate *state = PyModule_GetState(module);
229 if (tcsendbreak(fd, duration) == -1) {
230 return PyErr_SetFromErrno(state->TermiosError);
231 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000232
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200233 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000234}
235
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000236PyDoc_STRVAR(termios_tcdrain__doc__,
237"tcdrain(fd) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000238\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000239Wait until all output written to file descriptor fd has been transmitted.");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000240
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000241static PyObject *
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500242termios_tcdrain(PyObject *module, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000243{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000244 int fd;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000245 if (!PyArg_ParseTuple(args, "O&:tcdrain",
Serhiy Storchaka9975cc52020-10-09 23:00:45 +0300246 _PyLong_FileDescriptor_Converter, &fd)) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000247 return NULL;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500248 }
249
250 termiosmodulestate *state = PyModule_GetState(module);
251 if (tcdrain(fd) == -1) {
252 return PyErr_SetFromErrno(state->TermiosError);
253 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000254
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200255 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000256}
257
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000258PyDoc_STRVAR(termios_tcflush__doc__,
259"tcflush(fd, queue) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000260\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000261Discard queued data on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000262The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
263queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000264both queues. ");
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000265
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000266static PyObject *
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500267termios_tcflush(PyObject *module, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000268{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000269 int fd, queue;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000270 if (!PyArg_ParseTuple(args, "O&i:tcflush",
Serhiy Storchaka9975cc52020-10-09 23:00:45 +0300271 _PyLong_FileDescriptor_Converter, &fd, &queue)) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000272 return NULL;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500273 }
274
275 termiosmodulestate *state = PyModule_GetState(module);
276 if (tcflush(fd, queue) == -1) {
277 return PyErr_SetFromErrno(state->TermiosError);
278 }
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 *
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500292termios_tcflow(PyObject *module, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000293{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000294 int fd, action;
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000295 if (!PyArg_ParseTuple(args, "O&i:tcflow",
Serhiy Storchaka9975cc52020-10-09 23:00:45 +0300296 _PyLong_FileDescriptor_Converter, &fd, &action)) {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000297 return NULL;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -0500298 }
299
300 termiosmodulestate *state = PyModule_GetState(module);
301 if (tcflow(fd, action) == -1) {
302 return PyErr_SetFromErrno(state->TermiosError);
303 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000304
Serhiy Storchaka228b12e2017-01-23 09:47:21 +0200305 Py_RETURN_NONE;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000306}
307
308static PyMethodDef termios_methods[] =
309{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000310 {"tcgetattr", termios_tcgetattr,
311 METH_VARARGS, termios_tcgetattr__doc__},
312 {"tcsetattr", termios_tcsetattr,
313 METH_VARARGS, termios_tcsetattr__doc__},
314 {"tcsendbreak", termios_tcsendbreak,
315 METH_VARARGS, termios_tcsendbreak__doc__},
316 {"tcdrain", termios_tcdrain,
317 METH_VARARGS, termios_tcdrain__doc__},
318 {"tcflush", termios_tcflush,
319 METH_VARARGS, termios_tcflush__doc__},
320 {"tcflow", termios_tcflow,
321 METH_VARARGS, termios_tcflow__doc__},
322 {NULL, NULL}
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000323};
324
Fred Drakedf48d142001-02-27 21:22:39 +0000325
Fred Drake9ef7fa82001-03-01 21:54:49 +0000326#if defined(VSWTCH) && !defined(VSWTC)
327#define VSWTC VSWTCH
328#endif
329
330#if defined(VSWTC) && !defined(VSWTCH)
331#define VSWTCH VSWTC
332#endif
333
Fred Drakedf48d142001-02-27 21:22:39 +0000334static struct constant {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000335 char *name;
336 long value;
Fred Drakedf48d142001-02-27 21:22:39 +0000337} termios_constants[] = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000338 /* cfgetospeed(), cfsetospeed() constants */
339 {"B0", B0},
340 {"B50", B50},
341 {"B75", B75},
342 {"B110", B110},
343 {"B134", B134},
344 {"B150", B150},
345 {"B200", B200},
346 {"B300", B300},
347 {"B600", B600},
348 {"B1200", B1200},
349 {"B1800", B1800},
350 {"B2400", B2400},
351 {"B4800", B4800},
352 {"B9600", B9600},
353 {"B19200", B19200},
354 {"B38400", B38400},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000355#ifdef B57600
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000356 {"B57600", B57600},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000357#endif
358#ifdef B115200
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000359 {"B115200", B115200},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000360#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000361#ifdef B230400
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000362 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000363#endif
Antoine Pitroua78f74c2010-11-20 20:03:08 +0000364#ifdef B460800
365 {"B460800", B460800},
366#endif
367#ifdef B500000
368 {"B500000", B500000},
369#endif
370#ifdef B576000
371 {"B576000", B576000},
372#endif
373#ifdef B921600
374 {"B921600", B921600},
375#endif
376#ifdef B1000000
377 {"B1000000", B1000000},
378#endif
379#ifdef B1152000
380 {"B1152000", B1152000},
381#endif
382#ifdef B1500000
383 {"B1500000", B1500000},
384#endif
385#ifdef B2000000
386 {"B2000000", B2000000},
387#endif
388#ifdef B2500000
389 {"B2500000", B2500000},
390#endif
391#ifdef B3000000
392 {"B3000000", B3000000},
393#endif
394#ifdef B3500000
395 {"B3500000", B3500000},
396#endif
397#ifdef B4000000
398 {"B4000000", B4000000},
399#endif
400
Fred Drake9ef7fa82001-03-01 21:54:49 +0000401#ifdef CBAUDEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000402 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000403#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000404
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000405 /* tcsetattr() constants */
406 {"TCSANOW", TCSANOW},
407 {"TCSADRAIN", TCSADRAIN},
408 {"TCSAFLUSH", TCSAFLUSH},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000409#ifdef TCSASOFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000410 {"TCSASOFT", TCSASOFT},
Gregory P. Smithcafc22f2009-11-01 19:24:18 +0000411#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000412
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000413 /* tcflush() constants */
414 {"TCIFLUSH", TCIFLUSH},
415 {"TCOFLUSH", TCOFLUSH},
416 {"TCIOFLUSH", TCIOFLUSH},
Fred Drakedf48d142001-02-27 21:22:39 +0000417
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000418 /* tcflow() constants */
419 {"TCOOFF", TCOOFF},
420 {"TCOON", TCOON},
421 {"TCIOFF", TCIOFF},
422 {"TCION", TCION},
Fred Drakedf48d142001-02-27 21:22:39 +0000423
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000424 /* struct termios.c_iflag constants */
425 {"IGNBRK", IGNBRK},
426 {"BRKINT", BRKINT},
427 {"IGNPAR", IGNPAR},
428 {"PARMRK", PARMRK},
429 {"INPCK", INPCK},
430 {"ISTRIP", ISTRIP},
431 {"INLCR", INLCR},
432 {"IGNCR", IGNCR},
433 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000434#ifdef IUCLC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000435 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000436#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000437 {"IXON", IXON},
438 {"IXANY", IXANY},
439 {"IXOFF", IXOFF},
Thomas Wouters2b305242001-06-15 12:05:44 +0000440#ifdef IMAXBEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000441 {"IMAXBEL", IMAXBEL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000442#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000443
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000444 /* struct termios.c_oflag constants */
445 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000446#ifdef OLCUC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000447 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000448#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000449#ifdef ONLCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000450 {"ONLCR", ONLCR},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000451#endif
Fred Draked85556c2001-03-03 18:08:52 +0000452#ifdef OCRNL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000453 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000454#endif
455#ifdef ONOCR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000456 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000457#endif
458#ifdef ONLRET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000459 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000460#endif
461#ifdef OFILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000462 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000463#endif
464#ifdef OFDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000465 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000466#endif
467#ifdef NLDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000468 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000469#endif
470#ifdef CRDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000471 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000472#endif
473#ifdef TABDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000474 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000475#endif
476#ifdef BSDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000477 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000478#endif
479#ifdef VTDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000480 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000481#endif
482#ifdef FFDLY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000483 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000484#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000485
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000486 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000487#ifdef NL0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000488 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000489#endif
490#ifdef NL1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000491 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000492#endif
493#ifdef CR0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000494 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000495#endif
496#ifdef CR1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000497 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000498#endif
499#ifdef CR2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000500 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000501#endif
502#ifdef CR3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000503 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000504#endif
505#ifdef TAB0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000506 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000507#endif
508#ifdef TAB1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000509 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000510#endif
511#ifdef TAB2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000512 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000513#endif
514#ifdef TAB3
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000515 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000516#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000517#ifdef XTABS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000518 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000519#endif
Fred Draked85556c2001-03-03 18:08:52 +0000520#ifdef BS0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000521 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000522#endif
523#ifdef BS1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000524 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000525#endif
526#ifdef VT0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000527 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000528#endif
529#ifdef VT1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000530 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000531#endif
532#ifdef FF0
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000533 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000534#endif
535#ifdef FF1
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000536 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000537#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000538
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000539 /* struct termios.c_cflag constants */
540 {"CSIZE", CSIZE},
541 {"CSTOPB", CSTOPB},
542 {"CREAD", CREAD},
543 {"PARENB", PARENB},
544 {"PARODD", PARODD},
545 {"HUPCL", HUPCL},
546 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000547#ifdef CIBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000548 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000549#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000550#ifdef CRTSCTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000551 {"CRTSCTS", (long)CRTSCTS},
Fred Drakededbebf2001-03-02 06:50:58 +0000552#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000553
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000554 /* struct termios.c_cflag-related values (character size) */
555 {"CS5", CS5},
556 {"CS6", CS6},
557 {"CS7", CS7},
558 {"CS8", CS8},
Fred Drakedf48d142001-02-27 21:22:39 +0000559
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000560 /* struct termios.c_lflag constants */
561 {"ISIG", ISIG},
562 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000563#ifdef XCASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000564 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000565#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000566 {"ECHO", ECHO},
567 {"ECHOE", ECHOE},
568 {"ECHOK", ECHOK},
569 {"ECHONL", ECHONL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000570#ifdef ECHOCTL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000571 {"ECHOCTL", ECHOCTL},
Thomas Wouters2b305242001-06-15 12:05:44 +0000572#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000573#ifdef ECHOPRT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000574 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000575#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000576#ifdef ECHOKE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000577 {"ECHOKE", ECHOKE},
Thomas Wouters2b305242001-06-15 12:05:44 +0000578#endif
579#ifdef FLUSHO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000580 {"FLUSHO", FLUSHO},
Thomas Wouters2b305242001-06-15 12:05:44 +0000581#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000582 {"NOFLSH", NOFLSH},
583 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000584#ifdef PENDIN
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000585 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000586#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000587 {"IEXTEN", IEXTEN},
Fred Drakedf48d142001-02-27 21:22:39 +0000588
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000589 /* indexes into the control chars array returned by tcgetattr() */
590 {"VINTR", VINTR},
591 {"VQUIT", VQUIT},
592 {"VERASE", VERASE},
593 {"VKILL", VKILL},
594 {"VEOF", VEOF},
595 {"VTIME", VTIME},
596 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000597#ifdef VSWTC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000598 /* The #defines above ensure that if either is defined, both are,
599 * but both may be omitted by the system headers. ;-( */
600 {"VSWTC", VSWTC},
601 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000602#endif
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000603 {"VSTART", VSTART},
604 {"VSTOP", VSTOP},
605 {"VSUSP", VSUSP},
606 {"VEOL", VEOL},
Fred Draked0b625d2001-05-22 15:44:15 +0000607#ifdef VREPRINT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000608 {"VREPRINT", VREPRINT},
Fred Drake87068f12001-05-11 16:14:17 +0000609#endif
Fred Draked0b625d2001-05-22 15:44:15 +0000610#ifdef VDISCARD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000611 {"VDISCARD", VDISCARD},
Fred Drake87068f12001-05-11 16:14:17 +0000612#endif
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000613#ifdef VWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000614 {"VWERASE", VWERASE},
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000615#endif
Thomas Wouters2b305242001-06-15 12:05:44 +0000616#ifdef VLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000617 {"VLNEXT", VLNEXT},
Thomas Wouters2b305242001-06-15 12:05:44 +0000618#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000619#ifdef VEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000620 {"VEOL2", VEOL2},
Andrew MacIntyre7bf68332002-03-03 02:59:16 +0000621#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000622
Fred Drake55a00342001-03-26 17:14:02 +0000623
624#ifdef B460800
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000625 {"B460800", B460800},
Fred Drake55a00342001-03-26 17:14:02 +0000626#endif
Anthony Shaw7dc72b82020-01-04 23:56:31 +1100627#ifdef B500000
628 {"B500000", B500000},
629#endif
630#ifdef B576000
631 { "B576000", B576000},
632#endif
633#ifdef B921600
634 { "B921600", B921600},
635#endif
636#ifdef B1000000
637 { "B1000000", B1000000},
638#endif
639#ifdef B1152000
640 { "B1152000", B1152000},
641#endif
642#ifdef B1500000
643 { "B1500000", B1500000},
644#endif
645#ifdef B2000000
646 { "B2000000", B2000000},
647#endif
648#ifdef B2500000
649 { "B2500000", B2500000},
650#endif
651#ifdef B3000000
652 { "B3000000", B3000000},
653#endif
654#ifdef B3500000
655 { "B3500000", B3500000},
656#endif
657#ifdef B4000000
658 { "B4000000", B4000000},
659#endif
Fred Drake55a00342001-03-26 17:14:02 +0000660#ifdef CBAUD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000661 {"CBAUD", CBAUD},
Fred Drake55a00342001-03-26 17:14:02 +0000662#endif
663#ifdef CDEL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000664 {"CDEL", CDEL},
Fred Drake55a00342001-03-26 17:14:02 +0000665#endif
666#ifdef CDSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000667 {"CDSUSP", CDSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000668#endif
669#ifdef CEOF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000670 {"CEOF", CEOF},
Fred Drake55a00342001-03-26 17:14:02 +0000671#endif
672#ifdef CEOL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000673 {"CEOL", CEOL},
Fred Drake55a00342001-03-26 17:14:02 +0000674#endif
675#ifdef CEOL2
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000676 {"CEOL2", CEOL2},
Fred Drake55a00342001-03-26 17:14:02 +0000677#endif
678#ifdef CEOT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000679 {"CEOT", CEOT},
Fred Drake55a00342001-03-26 17:14:02 +0000680#endif
681#ifdef CERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000682 {"CERASE", CERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000683#endif
684#ifdef CESC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000685 {"CESC", CESC},
Fred Drake55a00342001-03-26 17:14:02 +0000686#endif
687#ifdef CFLUSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000688 {"CFLUSH", CFLUSH},
Fred Drake55a00342001-03-26 17:14:02 +0000689#endif
690#ifdef CINTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000691 {"CINTR", CINTR},
Fred Drake55a00342001-03-26 17:14:02 +0000692#endif
693#ifdef CKILL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000694 {"CKILL", CKILL},
Fred Drake55a00342001-03-26 17:14:02 +0000695#endif
696#ifdef CLNEXT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000697 {"CLNEXT", CLNEXT},
Fred Drake55a00342001-03-26 17:14:02 +0000698#endif
699#ifdef CNUL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000700 {"CNUL", CNUL},
Fred Drake55a00342001-03-26 17:14:02 +0000701#endif
702#ifdef COMMON
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000703 {"COMMON", COMMON},
Fred Drake55a00342001-03-26 17:14:02 +0000704#endif
705#ifdef CQUIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000706 {"CQUIT", CQUIT},
Fred Drake55a00342001-03-26 17:14:02 +0000707#endif
708#ifdef CRPRNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000709 {"CRPRNT", CRPRNT},
Fred Drake55a00342001-03-26 17:14:02 +0000710#endif
711#ifdef CSTART
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000712 {"CSTART", CSTART},
Fred Drake55a00342001-03-26 17:14:02 +0000713#endif
714#ifdef CSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000715 {"CSTOP", CSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000716#endif
717#ifdef CSUSP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000718 {"CSUSP", CSUSP},
Fred Drake55a00342001-03-26 17:14:02 +0000719#endif
720#ifdef CSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000721 {"CSWTCH", CSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000722#endif
723#ifdef CWERASE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000724 {"CWERASE", CWERASE},
Fred Drake55a00342001-03-26 17:14:02 +0000725#endif
726#ifdef EXTA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000727 {"EXTA", EXTA},
Fred Drake55a00342001-03-26 17:14:02 +0000728#endif
729#ifdef EXTB
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000730 {"EXTB", EXTB},
Fred Drake55a00342001-03-26 17:14:02 +0000731#endif
732#ifdef FIOASYNC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000733 {"FIOASYNC", FIOASYNC},
Fred Drake55a00342001-03-26 17:14:02 +0000734#endif
735#ifdef FIOCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000736 {"FIOCLEX", FIOCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000737#endif
738#ifdef FIONBIO
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000739 {"FIONBIO", FIONBIO},
Fred Drake55a00342001-03-26 17:14:02 +0000740#endif
741#ifdef FIONCLEX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000742 {"FIONCLEX", FIONCLEX},
Fred Drake55a00342001-03-26 17:14:02 +0000743#endif
744#ifdef FIONREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000745 {"FIONREAD", FIONREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000746#endif
747#ifdef IBSHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000748 {"IBSHIFT", IBSHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000749#endif
750#ifdef INIT_C_CC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000751 {"INIT_C_CC", INIT_C_CC},
Fred Drake55a00342001-03-26 17:14:02 +0000752#endif
753#ifdef IOCSIZE_MASK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000754 {"IOCSIZE_MASK", IOCSIZE_MASK},
Fred Drake55a00342001-03-26 17:14:02 +0000755#endif
756#ifdef IOCSIZE_SHIFT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000757 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
Fred Drake55a00342001-03-26 17:14:02 +0000758#endif
759#ifdef NCC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000760 {"NCC", NCC},
Fred Drake55a00342001-03-26 17:14:02 +0000761#endif
762#ifdef NCCS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000763 {"NCCS", NCCS},
Fred Drake55a00342001-03-26 17:14:02 +0000764#endif
765#ifdef NSWTCH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000766 {"NSWTCH", NSWTCH},
Fred Drake55a00342001-03-26 17:14:02 +0000767#endif
768#ifdef N_MOUSE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000769 {"N_MOUSE", N_MOUSE},
Fred Drake55a00342001-03-26 17:14:02 +0000770#endif
771#ifdef N_PPP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000772 {"N_PPP", N_PPP},
Fred Drake55a00342001-03-26 17:14:02 +0000773#endif
774#ifdef N_SLIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000775 {"N_SLIP", N_SLIP},
Fred Drake55a00342001-03-26 17:14:02 +0000776#endif
777#ifdef N_STRIP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000778 {"N_STRIP", N_STRIP},
Fred Drake55a00342001-03-26 17:14:02 +0000779#endif
780#ifdef N_TTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000781 {"N_TTY", N_TTY},
Fred Drake55a00342001-03-26 17:14:02 +0000782#endif
783#ifdef TCFLSH
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000784 {"TCFLSH", TCFLSH},
Fred Drake55a00342001-03-26 17:14:02 +0000785#endif
786#ifdef TCGETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000787 {"TCGETA", TCGETA},
Fred Drake55a00342001-03-26 17:14:02 +0000788#endif
789#ifdef TCGETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000790 {"TCGETS", TCGETS},
Fred Drake55a00342001-03-26 17:14:02 +0000791#endif
792#ifdef TCSBRK
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000793 {"TCSBRK", TCSBRK},
Fred Drake55a00342001-03-26 17:14:02 +0000794#endif
795#ifdef TCSBRKP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000796 {"TCSBRKP", TCSBRKP},
Fred Drake55a00342001-03-26 17:14:02 +0000797#endif
798#ifdef TCSETA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000799 {"TCSETA", TCSETA},
Fred Drake55a00342001-03-26 17:14:02 +0000800#endif
801#ifdef TCSETAF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000802 {"TCSETAF", TCSETAF},
Fred Drake55a00342001-03-26 17:14:02 +0000803#endif
804#ifdef TCSETAW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000805 {"TCSETAW", TCSETAW},
Fred Drake55a00342001-03-26 17:14:02 +0000806#endif
807#ifdef TCSETS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000808 {"TCSETS", TCSETS},
Fred Drake55a00342001-03-26 17:14:02 +0000809#endif
810#ifdef TCSETSF
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000811 {"TCSETSF", TCSETSF},
Fred Drake55a00342001-03-26 17:14:02 +0000812#endif
813#ifdef TCSETSW
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000814 {"TCSETSW", TCSETSW},
Fred Drake55a00342001-03-26 17:14:02 +0000815#endif
816#ifdef TCXONC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000817 {"TCXONC", TCXONC},
Fred Drake55a00342001-03-26 17:14:02 +0000818#endif
819#ifdef TIOCCONS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000820 {"TIOCCONS", TIOCCONS},
Fred Drake55a00342001-03-26 17:14:02 +0000821#endif
822#ifdef TIOCEXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000823 {"TIOCEXCL", TIOCEXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000824#endif
825#ifdef TIOCGETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000826 {"TIOCGETD", TIOCGETD},
Fred Drake55a00342001-03-26 17:14:02 +0000827#endif
828#ifdef TIOCGICOUNT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000829 {"TIOCGICOUNT", TIOCGICOUNT},
Fred Drake55a00342001-03-26 17:14:02 +0000830#endif
831#ifdef TIOCGLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000832 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000833#endif
834#ifdef TIOCGPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000835 {"TIOCGPGRP", TIOCGPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000836#endif
837#ifdef TIOCGSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000838 {"TIOCGSERIAL", TIOCGSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000839#endif
840#ifdef TIOCGSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000841 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000842#endif
843#ifdef TIOCGWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000844 {"TIOCGWINSZ", TIOCGWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000845#endif
846#ifdef TIOCINQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000847 {"TIOCINQ", TIOCINQ},
Fred Drake55a00342001-03-26 17:14:02 +0000848#endif
849#ifdef TIOCLINUX
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000850 {"TIOCLINUX", TIOCLINUX},
Fred Drake55a00342001-03-26 17:14:02 +0000851#endif
852#ifdef TIOCMBIC
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000853 {"TIOCMBIC", TIOCMBIC},
Fred Drake55a00342001-03-26 17:14:02 +0000854#endif
855#ifdef TIOCMBIS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000856 {"TIOCMBIS", TIOCMBIS},
Fred Drake55a00342001-03-26 17:14:02 +0000857#endif
858#ifdef TIOCMGET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000859 {"TIOCMGET", TIOCMGET},
Fred Drake55a00342001-03-26 17:14:02 +0000860#endif
861#ifdef TIOCMIWAIT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000862 {"TIOCMIWAIT", TIOCMIWAIT},
Fred Drake55a00342001-03-26 17:14:02 +0000863#endif
864#ifdef TIOCMSET
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000865 {"TIOCMSET", TIOCMSET},
Fred Drake55a00342001-03-26 17:14:02 +0000866#endif
867#ifdef TIOCM_CAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000868 {"TIOCM_CAR", TIOCM_CAR},
Fred Drake55a00342001-03-26 17:14:02 +0000869#endif
870#ifdef TIOCM_CD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000871 {"TIOCM_CD", TIOCM_CD},
Fred Drake55a00342001-03-26 17:14:02 +0000872#endif
873#ifdef TIOCM_CTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000874 {"TIOCM_CTS", TIOCM_CTS},
Fred Drake55a00342001-03-26 17:14:02 +0000875#endif
876#ifdef TIOCM_DSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000877 {"TIOCM_DSR", TIOCM_DSR},
Fred Drake55a00342001-03-26 17:14:02 +0000878#endif
879#ifdef TIOCM_DTR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000880 {"TIOCM_DTR", TIOCM_DTR},
Fred Drake55a00342001-03-26 17:14:02 +0000881#endif
882#ifdef TIOCM_LE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000883 {"TIOCM_LE", TIOCM_LE},
Fred Drake55a00342001-03-26 17:14:02 +0000884#endif
885#ifdef TIOCM_RI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000886 {"TIOCM_RI", TIOCM_RI},
Fred Drake55a00342001-03-26 17:14:02 +0000887#endif
888#ifdef TIOCM_RNG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000889 {"TIOCM_RNG", TIOCM_RNG},
Fred Drake55a00342001-03-26 17:14:02 +0000890#endif
891#ifdef TIOCM_RTS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000892 {"TIOCM_RTS", TIOCM_RTS},
Fred Drake55a00342001-03-26 17:14:02 +0000893#endif
894#ifdef TIOCM_SR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000895 {"TIOCM_SR", TIOCM_SR},
Fred Drake55a00342001-03-26 17:14:02 +0000896#endif
897#ifdef TIOCM_ST
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000898 {"TIOCM_ST", TIOCM_ST},
Fred Drake55a00342001-03-26 17:14:02 +0000899#endif
900#ifdef TIOCNOTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000901 {"TIOCNOTTY", TIOCNOTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000902#endif
903#ifdef TIOCNXCL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000904 {"TIOCNXCL", TIOCNXCL},
Fred Drake55a00342001-03-26 17:14:02 +0000905#endif
906#ifdef TIOCOUTQ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000907 {"TIOCOUTQ", TIOCOUTQ},
Fred Drake55a00342001-03-26 17:14:02 +0000908#endif
909#ifdef TIOCPKT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000910 {"TIOCPKT", TIOCPKT},
Fred Drake55a00342001-03-26 17:14:02 +0000911#endif
912#ifdef TIOCPKT_DATA
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000913 {"TIOCPKT_DATA", TIOCPKT_DATA},
Fred Drake55a00342001-03-26 17:14:02 +0000914#endif
915#ifdef TIOCPKT_DOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000916 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000917#endif
918#ifdef TIOCPKT_FLUSHREAD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000919 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
Fred Drake55a00342001-03-26 17:14:02 +0000920#endif
921#ifdef TIOCPKT_FLUSHWRITE
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000922 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
Fred Drake55a00342001-03-26 17:14:02 +0000923#endif
924#ifdef TIOCPKT_NOSTOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000925 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
Fred Drake55a00342001-03-26 17:14:02 +0000926#endif
927#ifdef TIOCPKT_START
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000928 {"TIOCPKT_START", TIOCPKT_START},
Fred Drake55a00342001-03-26 17:14:02 +0000929#endif
930#ifdef TIOCPKT_STOP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000931 {"TIOCPKT_STOP", TIOCPKT_STOP},
Fred Drake55a00342001-03-26 17:14:02 +0000932#endif
933#ifdef TIOCSCTTY
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000934 {"TIOCSCTTY", TIOCSCTTY},
Fred Drake55a00342001-03-26 17:14:02 +0000935#endif
936#ifdef TIOCSERCONFIG
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000937 {"TIOCSERCONFIG", TIOCSERCONFIG},
Fred Drake55a00342001-03-26 17:14:02 +0000938#endif
939#ifdef TIOCSERGETLSR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000940 {"TIOCSERGETLSR", TIOCSERGETLSR},
Fred Drake55a00342001-03-26 17:14:02 +0000941#endif
942#ifdef TIOCSERGETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000943 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000944#endif
945#ifdef TIOCSERGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000946 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000947#endif
948#ifdef TIOCSERGWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000949 {"TIOCSERGWILD", TIOCSERGWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000950#endif
951#ifdef TIOCSERSETMULTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000952 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
Fred Drake55a00342001-03-26 17:14:02 +0000953#endif
954#ifdef TIOCSERSWILD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000955 {"TIOCSERSWILD", TIOCSERSWILD},
Fred Drake55a00342001-03-26 17:14:02 +0000956#endif
957#ifdef TIOCSER_TEMT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000958 {"TIOCSER_TEMT", TIOCSER_TEMT},
Fred Drake55a00342001-03-26 17:14:02 +0000959#endif
960#ifdef TIOCSETD
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000961 {"TIOCSETD", TIOCSETD},
Fred Drake55a00342001-03-26 17:14:02 +0000962#endif
963#ifdef TIOCSLCKTRMIOS
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000964 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
Fred Drake55a00342001-03-26 17:14:02 +0000965#endif
966#ifdef TIOCSPGRP
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000967 {"TIOCSPGRP", TIOCSPGRP},
Fred Drake55a00342001-03-26 17:14:02 +0000968#endif
969#ifdef TIOCSSERIAL
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000970 {"TIOCSSERIAL", TIOCSSERIAL},
Fred Drake55a00342001-03-26 17:14:02 +0000971#endif
972#ifdef TIOCSSOFTCAR
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000973 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
Fred Drake55a00342001-03-26 17:14:02 +0000974#endif
975#ifdef TIOCSTI
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000976 {"TIOCSTI", TIOCSTI},
Fred Drake55a00342001-03-26 17:14:02 +0000977#endif
978#ifdef TIOCSWINSZ
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000979 {"TIOCSWINSZ", TIOCSWINSZ},
Fred Drake55a00342001-03-26 17:14:02 +0000980#endif
981#ifdef TIOCTTYGSTRUCT
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000982 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
Fred Drake55a00342001-03-26 17:14:02 +0000983#endif
984
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000985 /* sentinel */
986 {NULL, 0}
Fred Drakedf48d142001-02-27 21:22:39 +0000987};
988
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100989static int termiosmodule_traverse(PyObject *m, visitproc visit, void *arg) {
Hai Shif707d942020-03-16 21:15:01 +0800990 Py_VISIT(get_termios_state(m)->TermiosError);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100991 return 0;
992}
993
994static int termiosmodule_clear(PyObject *m) {
Hai Shif707d942020-03-16 21:15:01 +0800995 Py_CLEAR(get_termios_state(m)->TermiosError);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +0100996 return 0;
997}
998
999static void termiosmodule_free(void *m) {
1000 termiosmodule_clear((PyObject *)m);
1001}
Fred Drakedf48d142001-02-27 21:22:39 +00001002
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001003static int
1004termios_exec(PyObject *mod)
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001005{
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001006 struct constant *constant = termios_constants;
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001007 termiosmodulestate *state = get_termios_state(mod);
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001008 state->TermiosError = PyErr_NewException("termios.error", NULL, NULL);
1009 if (state->TermiosError == NULL) {
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001010 return -1;
Dino Viehlandbd0c7a12019-09-10 11:33:30 +01001011 }
1012 Py_INCREF(state->TermiosError);
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001013 if (PyModule_AddObject(mod, "error", state->TermiosError) < 0) {
1014 Py_DECREF(state->TermiosError);
1015 return -1;
1016 }
Fred Drakedf48d142001-02-27 21:22:39 +00001017
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001018 while (constant->name != NULL) {
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001019 if (PyModule_AddIntConstant(
1020 mod, constant->name, constant->value) < 0) {
1021 return -1;
1022 }
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001023 ++constant;
1024 }
Mohamed Koubaa15dcdb22020-09-08 03:59:15 -05001025 return 0;
1026}
1027
1028static PyModuleDef_Slot termios_slots[] = {
1029 {Py_mod_exec, termios_exec},
1030 {0, NULL}
1031};
1032
1033static struct PyModuleDef termiosmodule = {
1034 PyModuleDef_HEAD_INIT,
1035 .m_name = "termios",
1036 .m_doc = termios__doc__,
1037 .m_size = sizeof(termiosmodulestate),
1038 .m_methods = termios_methods,
1039 .m_slots = termios_slots,
1040 .m_traverse = termiosmodule_traverse,
1041 .m_clear = termiosmodule_clear,
1042 .m_free = termiosmodule_free,
1043};
1044
1045PyMODINIT_FUNC PyInit_termios(void)
1046{
1047 return PyModuleDef_Init(&termiosmodule);
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001048}