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
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 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 @@
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 @@
#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 */
diff --git a/configure b/configure
index 8293ee3..0418b84 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
-# From configure.in Revision: 1.136
+# From configure.in Revision: 1.137
# Guess values for system-dependent variables and create Makefiles.
# Generated automatically using autoconf version 2.13
@@ -3645,7 +3645,7 @@
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf \
sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname waitpid
+ truncate uname waitpid _getpty
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:3652: checking for $ac_func" >&5
diff --git a/configure.in b/configure.in
index 8315ca2..7a819e4 100644
--- a/configure.in
+++ b/configure.in
@@ -826,7 +826,7 @@
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf \
sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname waitpid)
+ truncate uname waitpid _getpty)
# check for openpty and forkpty