From ad3d96f8b792149d4a623584f8b403d40bd60331 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 14 Jan 2002 09:10:50 +0000 Subject: Patch from Brian Stafford to fixup support for Unix98 PTYs, and optionally exclude the older junk. --- libc/stdlib/getpt.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'libc/stdlib/getpt.c') diff --git a/libc/stdlib/getpt.c b/libc/stdlib/getpt.c index 0ee2d90d6..9e1f255bb 100644 --- a/libc/stdlib/getpt.c +++ b/libc/stdlib/getpt.c @@ -22,33 +22,45 @@ #include #include #include -#include + +#if !defined ASSUME_DEVPTS +# include /* Constant that identifies the `devpts' filesystem. */ -#define DEVPTS_SUPER_MAGIC 0x1cd1 +# define DEVPTS_SUPER_MAGIC 0x1cd1 /* Constant that identifies the `devfs' filesystem. */ -#define DEVFS_SUPER_MAGIC 0x1373 +# define DEVFS_SUPER_MAGIC 0x1373 +#endif /* Path to the master pseudo terminal cloning device. */ #define _PATH_DEVPTMX _PATH_DEV "ptmx" /* Directory containing the UNIX98 pseudo terminals. */ #define _PATH_DEVPTS _PATH_DEV "pts" +#if !defined UNIX98PTY_ONLY /* Prototype for function that opens BSD-style master pseudo-terminals. */ int __bsd_getpt (void); +#endif /* Open a master pseudo terminal and return its file descriptor. */ int getpt (void) { +#if !defined UNIX98PTY_ONLY static int have_no_dev_ptmx; +#endif int fd; +#if !defined UNIX98PTY_ONLY if (!have_no_dev_ptmx) +#endif { fd = open (_PATH_DEVPTMX, O_RDWR); if (fd != -1) { +#if defined ASSUME_DEVPTS + return fd; +#else struct statfs fsbuf; static int devpts_mounted; @@ -69,21 +81,28 @@ getpt (void) are not usable. */ close (fd); have_no_dev_ptmx = 1; +#endif } else { +#if !defined UNIX98PTY_ONLY if (errno == ENOENT || errno == ENODEV) have_no_dev_ptmx = 1; else +#endif return -1; } } +#if !defined UNIX98PTY_ONLY return __bsd_getpt (); +#endif } -#define PTYNAME1 "pqrstuvwxyzabcde"; -#define PTYNAME2 "0123456789abcdef"; +#if !defined UNIX98PTY_ONLY +# define PTYNAME1 "pqrstuvwxyzabcde"; +# define PTYNAME2 "0123456789abcdef"; -#define __getpt __bsd_getpt -#include "bsd_getpt.c" +# define __getpt __bsd_getpt +# include "bsd_getpt.c" +#endif -- cgit v1.2.3