summaryrefslogtreecommitdiff
path: root/libc/stdlib/getpt.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-01-14 09:10:50 +0000
committerEric Andersen <andersen@codepoet.org>2002-01-14 09:10:50 +0000
commitad3d96f8b792149d4a623584f8b403d40bd60331 (patch)
treea642f520af5de3923c499f886e068e0b9bbdcef3 /libc/stdlib/getpt.c
parent50b14f6bf77048f65377f26fe8737b9bfb8512a1 (diff)
Patch from Brian Stafford <brian@stafford.uklinux.net> to fixup
support for Unix98 PTYs, and optionally exclude the older junk.
Diffstat (limited to 'libc/stdlib/getpt.c')
-rw-r--r--libc/stdlib/getpt.c33
1 files changed, 26 insertions, 7 deletions
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 <stdlib.h>
#include <unistd.h>
#include <paths.h>
-#include <sys/statfs.h>
+
+#if !defined ASSUME_DEVPTS
+# include <sys/statfs.h>
/* 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