[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] posix_openpt: new module
From: |
Bruno Haible |
Subject: |
Re: [PATCH] posix_openpt: new module |
Date: |
Fri, 21 Oct 2011 02:44:59 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
Eric Blake wrote:
> +2011-10-17 Eric Blake <address@hidden>
> +
> + posix_openpt: new module
> + * modules/posix_openpt: New module.
> + * m4/posix_openpt.m4: New file.
> + * lib/posix_openpt.c: Likewise.
> + * m4/stdlib_h.m4 (gl_STDLIB_H): Check for decl.
> + (gl_STDLIB_H_DEFAULTS): Set defaults.
> + * modules/stdlib (Makefile.am): Substitute macros.
> + * lib/stdlib.in.h (posix_openpt): Declare.
> + * MODULES.html.sh (systems lacking POSIX:2008): Document it.
> + * doc/posix-functions/posix_openpt.texi (posix_openpt): Likewise.
> + * modules/posix_openpt-tests: New test module.
> + * tests/test-posix_openpt.c: New test.
But now, we have code duplication between lib/posix_openpt.c and lib/openpty.c.
This fixes it:
2011-10-20 Bruno Haible <address@hidden>
openpty, posix_openpt: Remove code duplication.
* lib/posix_openpt.c: Add comments about platforms, from lib/openpty.c.
* lib/openpty.c: Include <stdlib.h>.
(openpty): Use posix_openpt on all platforms except IRIX.
* modules/openpty (Depends-on): Add posix_openpt. Add conditions.
--- lib/openpty.c.orig Fri Oct 21 02:35:39 2011
+++ lib/openpty.c Thu Oct 20 15:24:33 2011
@@ -35,6 +35,7 @@
#else /* AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw */
# include <fcntl.h>
+# include <stdlib.h>
# include <string.h>
# include <sys/ioctl.h>
# include <termios.h>
@@ -59,45 +60,11 @@
# 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,
--- lib/posix_openpt.c.orig Fri Oct 21 02:35:39 2011
+++ lib/posix_openpt.c Thu Oct 20 23:14:23 2011
@@ -26,6 +26,25 @@
# include <sys/tty.h>
#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 @@
/* 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;
--- modules/openpty.orig Fri Oct 21 02:35:39 2011
+++ modules/openpty Thu Oct 20 12:23:50 2011
@@ -8,8 +8,9 @@
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
--
In memoriam Eduard Brücklmeier <http://en.wikipedia.org/wiki/Eduard_Brücklmeier>