From: Bruno Haible Date: Fri, 21 Oct 2011 00:45:21 +0000 (+0200) Subject: openpty, posix_openpt: Remove code duplication. X-Git-Tag: v0.1~1546 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=362dd1d5ec44fbfeadb896d02b0b192e80a22f7e;p=gnulib.git openpty, posix_openpt: Remove code duplication. * lib/posix_openpt.c: Add comments about platforms, from lib/openpty.c. * lib/openpty.c: Include . (openpty): Use posix_openpt on all platforms except IRIX. * modules/openpty (Depends-on): Add posix_openpt. Add conditions. --- diff --git a/ChangeLog b/ChangeLog index c670c9c17b..f44038b5a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-20 Bruno Haible + + openpty, posix_openpt: Remove code duplication. + * lib/posix_openpt.c: Add comments about platforms, from lib/openpty.c. + * lib/openpty.c: Include . + (openpty): Use posix_openpt on all platforms except IRIX. + * modules/openpty (Depends-on): Add posix_openpt. Add conditions. + 2011-10-20 Bruno Haible unlockpt: Detect invalid argument. diff --git a/lib/openpty.c b/lib/openpty.c index c6e75c6241..c398db5e69 100644 --- a/lib/openpty.c +++ b/lib/openpty.c @@ -35,6 +35,7 @@ rpl_openpty (int *amaster, int *aslave, char *name, #else /* AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw */ # include +# include # include # include # include @@ -59,45 +60,11 @@ openpty (int *amaster, int *aslave, char *name, # else /* AIX 5.1, HP-UX 11, Solaris 10, mingw */ -# if HAVE_POSIX_OPENPT /* Solaris 10 */ - + /* This call uses the 'posix_openpt' module. */ master = posix_openpt (O_RDWR | O_NOCTTY); if (master < 0) return -1; -# else /* AIX 5.1, HP-UX 11, Solaris 9, mingw */ - -# ifdef _AIX /* AIX */ - - master = open ("/dev/ptc", O_RDWR | O_NOCTTY); - if (master < 0) - return -1; - -# else /* HP-UX 11, Solaris 9, mingw */ - - /* HP-UX, Solaris have /dev/ptmx. - HP-UX also has /dev/ptym/clone, but this should not be needed. - Linux also has /dev/ptmx, but Linux already has openpty(). - MacOS X also has /dev/ptmx, but MacOS X already has openpty(). - OSF/1 also has /dev/ptmx and /dev/ptmx_bsd, but OSF/1 already has - openpty(). */ - master = open ("/dev/ptmx", O_RDWR | O_NOCTTY); - if (master < 0) - return -1; - -# endif - -# endif - - /* If all this does not work, we could try to open, one by one: - - On MacOS X: /dev/pty[p-w][0-9a-f] - - On *BSD: /dev/pty[p-sP-S][0-9a-v] - - On Minix: /dev/pty[p-q][0-9a-f] - - On AIX: /dev/ptyp[0-9a-f] - - On HP-UX: /dev/pty[p-r][0-9a-f] - - On OSF/1: /dev/pty[p-q][0-9a-f] - - On Solaris: /dev/pty[p-r][0-9a-f] - */ # endif /* This call does not require a dependency to the 'grantpt' module, diff --git a/lib/posix_openpt.c b/lib/posix_openpt.c index d2e585a68f..137db713f5 100644 --- a/lib/posix_openpt.c +++ b/lib/posix_openpt.c @@ -26,6 +26,25 @@ # include #endif +/* posix_openpt() is already provided on + glibc >= 2.2.1 (but is a stub on GNU/Hurd), + MacOS X >= 10.4, + FreeBSD >= 5.1 (lived in src/lib/libc/stdlib/grantpt.c before 8.0), + NetBSD >= 3.0, + AIX >= 5.2, HP-UX >= 11.31, Solaris >= 10, Cygwin >= 1.7. + Thus, this replacement function is compiled on + MacOS X 10.3, OpenBSD 4.9, Minix 3.1.8, + AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, + Cygwin 1.5.x, mingw, MSVC 9, Interix 3.5, BeOS. + Among these: + - AIX has /dev/ptc. + - HP-UX 10..11, IRIX 6.5, OSF/1 5.1, Solaris 2.6..9, Cygwin 1.5 + have /dev/ptmx. + - HP-UX 10..11 also has /dev/ptym/clone, but this should not be needed. + - OpenBSD 4.9 has /dev/ptm and the PTMGET ioctl. + - Minix 3.1.8 have a list of pseudo-terminal devices in /dev. + - On native Windows, there are no ttys at all. */ + int posix_openpt (int flags) { @@ -73,6 +92,16 @@ posix_openpt (int flags) /* Most systems that lack posix_openpt() have /dev/ptmx. */ master = open ("/dev/ptmx", flags); + /* If all this does not work, we could try to open, one by one: + - On MacOS X: /dev/pty[p-w][0-9a-f] + - On *BSD: /dev/pty[p-sP-S][0-9a-v] + - On Minix: /dev/pty[p-q][0-9a-f] + - On AIX: /dev/ptyp[0-9a-f] + - On HP-UX: /dev/pty[p-r][0-9a-f] + - On OSF/1: /dev/pty[p-q][0-9a-f] + - On Solaris: /dev/pty[p-r][0-9a-f] + */ + #endif return master; diff --git a/modules/openpty b/modules/openpty index bf51b7f377..8d174da7cb 100644 --- a/modules/openpty +++ b/modules/openpty @@ -8,8 +8,9 @@ m4/pty.m4 Depends-on: pty extensions -fcntl-h -ioctl +fcntl-h [test $HAVE_OPENPTY = 0 || test $REPLACE_OPENPTY = 1] +posix_openpt [test $HAVE_OPENPTY = 0 || test $REPLACE_OPENPTY = 1] +ioctl [test $HAVE_OPENPTY = 0 || test $REPLACE_OPENPTY = 1] configure.ac: gl_FUNC_OPENPTY