diff options
author | Bruno Haible <bruno@clisp.org> | 2011-10-20 17:44:40 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2011-10-20 17:46:35 +0200 |
commit | 3b50d1963aa9a19cf75a6fe8950d8647d1232105 (patch) | |
tree | 5955c70884b20fd26ce67d6ae053957c031a3ad3 /lib/posix_openpt.c | |
parent | 9ad470eff9f0d4af8ac1c67881a798c180d4a6df (diff) | |
download | gnulib-3b50d1963aa9a19cf75a6fe8950d8647d1232105.tar.gz |
posix_openpt: Support for OpenBSD.
* lib/posix_openpt.c [OpenBSD]: Include <sys/ioctl.h>, <sys/tty.h>.
(posix_openpt) [OpenBSD]: New code.
* lib/grantpt.c: Include <fcntl.h>.
(grantpt) [OpenBSD]: Only test whether fd is valid, nothing else.
* modules/grantpt (Depends-on): Add fcntl-h.
Diffstat (limited to 'lib/posix_openpt.c')
-rw-r--r-- | lib/posix_openpt.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/posix_openpt.c b/lib/posix_openpt.c index 19cd0b6c21..d2e585a68f 100644 --- a/lib/posix_openpt.c +++ b/lib/posix_openpt.c @@ -19,8 +19,12 @@ /* Specification. */ #include <stdlib.h> -#include <fcntl.h> #include <errno.h> +#include <fcntl.h> +#if defined __OpenBSD__ +# include <sys/ioctl.h> +# include <sys/tty.h> +#endif int posix_openpt (int flags) @@ -37,7 +41,34 @@ posix_openpt (int flags) master = -1; errno = ENOSYS; -#else /* MacOS, OpenBSD, HP-UX, IRIX, Solaris 9, Cygwin 1.5 */ +#elif defined __OpenBSD__ + + /* On OpenBSD, master and slave of a pseudo-terminal are allocated together, + by opening /dev/ptm and applying the PTMGET ioctl to it. */ + int fd; + struct ptmget data; + + fd = open (PATH_PTMDEV, O_RDWR); + if (fd >= 0) + { + if (ioctl (fd, PTMGET, &data) >= 0) + { + master = data.cfd; + close (data.sfd); + close (fd); + } + else + { + int saved_errno = errno; + close (fd); + errno = saved_errno; + master = -1; + } + } + else + master = -1; + +#else /* MacOS X, Minix, HP-UX, IRIX, OSF/1, Solaris 9, Cygwin 1.5 */ /* Most systems that lack posix_openpt() have /dev/ptmx. */ master = open ("/dev/ptmx", flags); |