summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2000-07-14 14:28:33 (GMT)
committerThomas Wouters <thomas@python.org>2000-07-14 14:28:33 (GMT)
commit70c21a1603091d58036ea6b91f106496d20f12f4 (patch)
tree30148a8b1a4a47822fa71d5980a4899feadbfa0d /Modules/posixmodule.c
parent649685ad9bc03b8d7576f7bf8418dce34a5060ad (diff)
downloadcpython-70c21a1603091d58036ea6b91f106496d20f12f4.zip
cpython-70c21a1603091d58036ea6b91f106496d20f12f4.tar.gz
cpython-70c21a1603091d58036ea6b91f106496d20f12f4.tar.bz2
Move (actually copy) support for the sgi._getpty() function into
posix.openpty(). And conveniently also check if CVS write access really works. Closes SF patch #100722
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 5b4a867..93f9ea9 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1706,9 +1706,9 @@ extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
extern int forkpty(int *, char *, struct termios *, struct winsize *);
#endif /* HAVE_LIBUTIL_H */
#endif /* HAVE_PTY_H */
-#endif /* defined(HAVE_OPENPTY) or defined(HAVE_FORKPTY) */
+#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
-#ifdef HAVE_OPENPTY
+#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY)
static char posix_openpty__doc__[] =
"openpty() -> (master_fd, slave_fd)\n\
Open a pseudo-terminal, returning open fd's for both master and slave end.\n";
@@ -1717,13 +1717,32 @@ static PyObject *
posix_openpty(PyObject *self, PyObject *args)
{
int master_fd, slave_fd;
+#ifndef HAVE_OPENPTY
+ char * slave_name;
+ /* SGI apparently needs this forward declaration */
+ extern char * _getpty(int *, int, mode_t, int);
+#endif
+
if (!PyArg_ParseTuple(args, ":openpty"))
return NULL;
+
+#ifdef HAVE_OPENPTY
if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
return posix_error();
+#else
+ slave_name = _getpty(&master_fd, O_RDWR, 0666, 0);
+ if (slave_name == NULL)
+ return posix_error();
+
+ slave_fd = open(slave_name, O_RDWR);
+ if (slave_fd < 0)
+ return posix_error();
+#endif /* defined(HAVE_OPENPTY) */
+
return Py_BuildValue("(ii)", master_fd, slave_fd);
+
}
-#endif
+#endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) */
#ifdef HAVE_FORKPTY
static char posix_forkpty__doc__[] =
@@ -4926,9 +4945,9 @@ static PyMethodDef posix_methods[] = {
#ifdef HAVE_FORK
{"fork", posix_fork, METH_VARARGS, posix_fork__doc__},
#endif /* HAVE_FORK */
-#ifdef HAVE_OPENPTY
+#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY)
{"openpty", posix_openpty, METH_VARARGS, posix_openpty__doc__},
-#endif /* HAVE_OPENPTY */
+#endif /* HAVE_OPENPTY || HAVE__GETPTY */
#ifdef HAVE_FORKPTY
{"forkpty", posix_forkpty, METH_VARARGS, posix_forkpty__doc__},
#endif /* HAVE_FORKPTY */