summaryrefslogtreecommitdiff
path: root/libc/stdlib/grantpt.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/grantpt.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/grantpt.c')
-rw-r--r--libc/stdlib/grantpt.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/libc/stdlib/grantpt.c b/libc/stdlib/grantpt.c
index 7aa49fcd5..d49f0af4f 100644
--- a/libc/stdlib/grantpt.c
+++ b/libc/stdlib/grantpt.c
@@ -18,6 +18,11 @@
#include <limits.h>
#include <stdlib.h>
+
+/* If ASSUME_DEVPTS is defined, grantpt() reduces to a stub since we
+ assume that the devfs/devpts filesystem automatically manages the
+ permissions. */
+#if !defined ASSUME_DEVPTS
#include <sys/statfs.h>
/* Constant that identifies the `devpts' filesystem. */
@@ -34,18 +39,21 @@ int __unix_grantpt (int fd);
pseudo terminal in a safe way. */
static int pts_name (int fd, char **pts, size_t buf_len);
+#endif
+
/* Change the ownership and access permission of the slave pseudo
terminal associated with the master pseudo terminal specified
by FD. */
int
grantpt (int fd)
{
+#if !defined ASSUME_DEVPTS
struct statfs fsbuf;
-#ifdef PATH_MAX
+# ifdef PATH_MAX
char _buf[PATH_MAX];
-#else
+# else
char _buf[512];
-#endif
+# endif
char *buf = _buf;
if (pts_name (fd, &buf, sizeof (_buf)))
@@ -56,11 +64,13 @@ grantpt (int fd)
/* If the slave pseudo terminal lives on a `devpts' filesystem, the
ownership and access permission are already set. */
- if (fsbuf.f_type == DEVPTS_SUPER_MAGIC || fsbuf.f_type == DEVFS_SUPER_MAGIC)
- return 0;
-
+ if (fsbuf.f_type != DEVPTS_SUPER_MAGIC && fsbuf.f_type != DEVFS_SUPER_MAGIC)
return __unix_grantpt (fd);
+#endif
+ return 0;
}
-#define grantpt __unix_grantpt
-#include "unix_grantpt.c"
+#if !defined ASSUME_DEVPTS
+# define grantpt __unix_grantpt
+# include "unix_grantpt.c"
+#endif