[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.136,2.137

Fred L. Drake python-dev@python.org
2000年6月28日 09:40:40 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv20497/Modules
Modified Files:
	posixmodule.c 
Log Message:
Thomas Wouters <thomas@xs4all.net>:
This patch adds the openpty() and forkpty() library calls to posixmodule.c,
when they are available on the target 
system. (glibc-2.1-based Linux systems, FreeBSD and BSDI at least, probably
the other BSD-based systems as well.)
Lib/pty.py is also rewritten to use openpty when available, but falls
back to the old SGI method or the "manual" BSD open-a-pty
code. Openpty() is necessary to use the Unix98 ptys under Linux 2.2,
or when using non-standard tty names under (at least) BSDI, which is
why I needed it, myself ;-) forkpty() is included for symmetry.
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.136
retrieving revision 2.137
diff -C2 -r2.136 -r2.137
*** posixmodule.c	2000年06月06日 20:52:17	2.136
--- posixmodule.c	2000年06月28日 16:40:38	2.137
***************
*** 1732,1735 ****
--- 1732,1793 ----
 #endif
 
+ #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
+ #ifdef HAVE_PTY_H
+ #include <pty.h>
+ #else
+ #ifdef HAVE_LIBUTIL_H
+ #include <libutil.h>
+ #else
+ /* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
+ functions, eventhough they are included in libutil. */
+ #include <termios.h>
+ 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) */
+ 
+ #ifdef HAVE_OPENPTY
+ 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";
+ 
+ static PyObject *
+ posix_openpty(self, args)
+ 	PyObject *self;
+ 	PyObject *args;
+ {
+ 	int master_fd, slave_fd;
+ 	if (!PyArg_ParseTuple(args, ":openpty"))
+ 		return NULL;
+ 	if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
+ 		return posix_error();
+ 	return Py_BuildValue("(ii)", master_fd, slave_fd);
+ }
+ #endif
+ 
+ #ifdef HAVE_FORKPTY
+ static char posix_forkpty__doc__[] =
+ "forkpty() -> (pid, master_fd)\n\
+ Fork a new process with a new pseudo-terminal as controlling tty.\n\n\
+ Like fork(), return 0 as pid to child process, and PID of child to parent.\n\
+ To both, return fd of newly opened pseudo-terminal.\n";
+ 
+ static PyObject *
+ posix_forkpty(self, args)
+ 	PyObject *self;
+ 	PyObject *args;
+ {
+ 	int master_fd, pid;
+ 	
+ 	if (!PyArg_ParseTuple(args, ":forkpty"))
+ 		return NULL;
+ 	pid = forkpty(&master_fd, NULL, NULL, NULL);
+ 	if (pid == -1)
+ 		return posix_error();
+ 	PyOS_AfterFork();
+ 	return Py_BuildValue("(ii)", pid, master_fd);
+ }
+ #endif
 
 #ifdef HAVE_GETEGID
***************
*** 4515,4518 ****
--- 4573,4582 ----
 	{"fork",	posix_fork, METH_VARARGS, posix_fork__doc__},
 #endif /* HAVE_FORK */
+ #ifdef HAVE_OPENPTY
+ 	{"openpty",	posix_openpty, METH_VARARGS, posix_openpty__doc__},
+ #endif /* HAVE_OPENPTY */
+ #ifdef HAVE_FORKPTY
+ 	{"forkpty",	posix_forkpty, METH_VARARGS, posix_forkpty__doc__},
+ #endif /* HAVE_FORKPTY */
 #ifdef HAVE_GETEGID
 	{"getegid",	posix_getegid, METH_VARARGS, posix_getegid__doc__},

AltStyle によって変換されたページ (->オリジナル) /