ソースを参照

Patch from Brian Stafford <brian@stafford.uklinux.net> to fixup
support for Unix98 PTYs, and optionally exclude the older junk.

Eric Andersen 22 年 前
コミット
ad3d96f8b7

+ 10 - 0
Makefile

@@ -161,6 +161,16 @@ uClibc_config.h: Makefile Config
 	else \
 	else \
 	    echo "#undef __UCLIBC_HAVE_LFS__" >> uClibc_config.h ; \
 	    echo "#undef __UCLIBC_HAVE_LFS__" >> uClibc_config.h ; \
 	fi
 	fi
+	@if [ "$(UNIX98PTY_ONLY)" = "true" ] ; then \
+	    echo "#define UNIX98PTY_ONLY 1" >> uClibc_config.h ; \
+	else \
+	    echo "#undef UNIX98PTY_ONLY" >> uClibc_config.h ; \
+	fi
+	@if [ "$(ASSUME_DEVPTS)" = "true" ] ; then \
+	    echo "#define ASSUME_DEVPTS 1" >> uClibc_config.h ; \
+	else \
+	    echo "#undef ASSUME_DEVPTS" >> uClibc_config.h ; \
+	fi
 
 
 subdirs: $(patsubst %, _dir_%, $(DIRS))
 subdirs: $(patsubst %, _dir_%, $(DIRS))
 
 

+ 15 - 3
extra/Configs/Config.arm

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = #arm-linux-
 CROSS = #arm-linux-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -128,10 +129,21 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
-# If you want to compile the library as PIC code, turn this on.
-DOPIC = true
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
 
 
 
 
+# If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
+DOPIC = false
 
 
 # Enable support for shared libraries?  If this is false, you can
 # Enable support for shared libraries?  If this is false, you can
 # ignore all the rest of the options in this file...
 # ignore all the rest of the options in this file...

+ 15 - 3
extra/Configs/Config.cross.arm.uclinux

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = arm-elf-
 CROSS = arm-elf-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -124,10 +125,21 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
-# If you want to compile the library as PIC code, turn this on.
-DOPIC = false
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
 
 
 
 
+# If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
+DOPIC = false
 
 
 # Enable support for shared libraries?  If this is false, you can
 # Enable support for shared libraries?  If this is false, you can
 # ignore all the rest of the options in this file...
 # ignore all the rest of the options in this file...

+ 15 - 3
extra/Configs/Config.i386

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = #$(TARGET_ARCH)-linux-
 CROSS = #$(TARGET_ARCH)-linux-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -124,10 +125,21 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
-# If you want to compile the library as PIC code, turn this on.
-DOPIC = false
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
 
 
 
 
+# If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
+DOPIC = false
 
 
 # Enable support for shared libraries?  If this is false, you can
 # Enable support for shared libraries?  If this is false, you can
 # ignore all the rest of the options in this file...
 # ignore all the rest of the options in this file...

+ 15 - 1
extra/Configs/Config.m68k

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 #CROSS = m68k-elf-
 #CROSS = m68k-elf-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -124,7 +125,20 @@ INCLUDE_RPC = true
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
+
+
 # If you want to compile the library as PIC code, turn this on.
 # If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
 DOPIC = false
 DOPIC = false
 
 
 #
 #

+ 15 - 1
extra/Configs/Config.m68k.coff

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = m68k-coff-
 CROSS = m68k-coff-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -124,7 +125,20 @@ INCLUDE_RPC = true
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
+
+
 # If you want to compile the library as PIC code, turn this on.
 # If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
 DOPIC = false
 DOPIC = false
 
 
 #
 #

+ 15 - 3
extra/Configs/Config.mips

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = mipsel-linux-
 CROSS = mipsel-linux-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -123,10 +124,21 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
-# If you want to compile the library as PIC code, turn this on.
-DOPIC = false
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
 
 
 
 
+# If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
+DOPIC = false
 
 
 # Enable support for shared libraries?  If this is false, you can
 # Enable support for shared libraries?  If this is false, you can
 # ignore all the rest of the options in this file...
 # ignore all the rest of the options in this file...

+ 15 - 3
extra/Configs/Config.mipsel

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = mipsel-linux-
 CROSS = mipsel-linux-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -123,10 +124,21 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
-# If you want to compile the library as PIC code, turn this on.
-DOPIC = false
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
 
 
 
 
+# If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
+DOPIC = false
 
 
 # Enable support for shared libraries?  If this is false, you can
 # Enable support for shared libraries?  If this is false, you can
 # ignore all the rest of the options in this file...
 # ignore all the rest of the options in this file...

+ 15 - 3
extra/Configs/Config.powerpc

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = #$(TARGET_ARCH)-linux-
 CROSS = #$(TARGET_ARCH)-linux-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -124,10 +125,21 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
-# If you want to compile the library as PIC code, turn this on.
-DOPIC = false
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
 
 
 
 
+# If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
+DOPIC = false
 
 
 # Enable support for shared libraries?  If this is false, you can
 # Enable support for shared libraries?  If this is false, you can
 # ignore all the rest of the options in this file...
 # ignore all the rest of the options in this file...

+ 15 - 3
extra/Configs/Config.sh

@@ -25,10 +25,11 @@
 # other sundry sources.  Files within this library are copyright by their
 # other sundry sources.  Files within this library are copyright by their
 # respective copyright holders.
 # respective copyright holders.
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = /usr/cygnus/yapp-001013/H-i686-pc-linux-gnulibc2.1/bin/sh-linux-gnu-
 CROSS = /usr/cygnus/yapp-001013/H-i686-pc-linux-gnulibc2.1/bin/sh-linux-gnu-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -148,10 +149,21 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
-# If you want to compile the library as PIC code, turn this on.
-DOPIC = false
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
 
 
 
 
+# If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
+DOPIC = false
 
 
 # Enable support for shared libraries?  If this is false, you can
 # Enable support for shared libraries?  If this is false, you can
 # ignore all the rest of the options in this file...
 # ignore all the rest of the options in this file...

+ 15 - 1
extra/Configs/Config.v850e

@@ -30,10 +30,11 @@ PROJ_UCLINUX=/proj/soft2/uclinux
 # Cross compile on i386-pc-linux-gnu
 # Cross compile on i386-pc-linux-gnu
 DESTDIR=$(PROJ_UCLINUX)/i386-pc-linux-gnu/v850e-linux
 DESTDIR=$(PROJ_UCLINUX)/i386-pc-linux-gnu/v850e-linux
 
 
+NATIVE_CC = gcc
+
 # If you are running a cross compiler, you may want to set this
 # If you are running a cross compiler, you may want to set this
 # to something more interesting...  Target architecture is determined
 # to something more interesting...  Target architecture is determined
 # by asking this compiler what arch it compiles stuff for.
 # by asking this compiler what arch it compiles stuff for.
-NATIVE_CC = gcc
 CROSS = v850e-elf-
 CROSS = v850e-elf-
 CC = $(CROSS)gcc
 CC = $(CROSS)gcc
 AR = $(CROSS)ar
 AR = $(CROSS)ar
@@ -129,7 +130,20 @@ INCLUDE_RPC = false
 # Protocol: IP version 6, enable this.  This is off by default.
 # Protocol: IP version 6, enable this.  This is off by default.
 INCLUDE_IPV6 = false
 INCLUDE_IPV6 = false
 
 
+# If you want to support only Unix 98 PTYs enable this.  Some older
+# applications may need this disabled.  For most current programs, 
+# you can generally leave this true.
+UNIX98PTY_ONLY = true
+
+# Enable this if /dev/pts is on a devpts or devfs file system.  Both
+# these filesystems automatically manage permissions on the /dev/pts 
+# devices.  You may need to mount this fs on /dev/pts for this to work. 
+# This is true by default.
+ASSUME_DEVPTS = true
+
+
 # If you want to compile the library as PIC code, turn this on.
 # If you want to compile the library as PIC code, turn this on.
+# This is automagically enabled when HAVE_SHARED is true
 DOPIC = false
 DOPIC = false
 
 
 # String prefixed to all user symbol names by the C compiler.  Usually
 # String prefixed to all user symbol names by the C compiler.  Usually

+ 26 - 7
libc/stdlib/getpt.c

@@ -22,33 +22,45 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <paths.h>
 #include <paths.h>
-#include <sys/statfs.h>
+
+#if !defined ASSUME_DEVPTS
+# include <sys/statfs.h>
 
 
 /* Constant that identifies the `devpts' filesystem.  */
 /* Constant that identifies the `devpts' filesystem.  */
-#define DEVPTS_SUPER_MAGIC	0x1cd1
+# define DEVPTS_SUPER_MAGIC	0x1cd1
 /* Constant that identifies the `devfs' filesystem.  */
 /* 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.  */
 /* Path to the master pseudo terminal cloning device.  */
 #define _PATH_DEVPTMX _PATH_DEV "ptmx"
 #define _PATH_DEVPTMX _PATH_DEV "ptmx"
 /* Directory containing the UNIX98 pseudo terminals.  */
 /* Directory containing the UNIX98 pseudo terminals.  */
 #define _PATH_DEVPTS _PATH_DEV "pts"
 #define _PATH_DEVPTS _PATH_DEV "pts"
 
 
+#if !defined UNIX98PTY_ONLY
 /* Prototype for function that opens BSD-style master pseudo-terminals.  */
 /* Prototype for function that opens BSD-style master pseudo-terminals.  */
 int __bsd_getpt (void);
 int __bsd_getpt (void);
+#endif
 
 
 /* Open a master pseudo terminal and return its file descriptor.  */
 /* Open a master pseudo terminal and return its file descriptor.  */
 int
 int
 getpt (void)
 getpt (void)
 {
 {
+#if !defined UNIX98PTY_ONLY
   static int have_no_dev_ptmx;
   static int have_no_dev_ptmx;
+#endif
   int fd;
   int fd;
 
 
+#if !defined UNIX98PTY_ONLY
   if (!have_no_dev_ptmx)
   if (!have_no_dev_ptmx)
+#endif
     {
     {
       fd = open (_PATH_DEVPTMX, O_RDWR);
       fd = open (_PATH_DEVPTMX, O_RDWR);
       if (fd != -1)
       if (fd != -1)
 	{
 	{
+#if defined ASSUME_DEVPTS
+	  return fd;
+#else
 	  struct statfs fsbuf;
 	  struct statfs fsbuf;
 	  static int devpts_mounted;
 	  static int devpts_mounted;
 
 
@@ -69,21 +81,28 @@ getpt (void)
              are not usable.  */
              are not usable.  */
 	  close (fd);
 	  close (fd);
 	  have_no_dev_ptmx = 1;
 	  have_no_dev_ptmx = 1;
+#endif
 	}
 	}
       else
       else
 	{
 	{
+#if !defined UNIX98PTY_ONLY
 	  if (errno == ENOENT || errno == ENODEV)
 	  if (errno == ENOENT || errno == ENODEV)
 	    have_no_dev_ptmx = 1;
 	    have_no_dev_ptmx = 1;
 	  else
 	  else
+#endif
 	    return -1;
 	    return -1;
 	}
 	}
     }
     }
 
 
+#if !defined UNIX98PTY_ONLY
   return __bsd_getpt ();
   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

+ 18 - 8
libc/stdlib/grantpt.c

@@ -18,6 +18,11 @@
 
 
 #include <limits.h>
 #include <limits.h>
 #include <stdlib.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>
 #include <sys/statfs.h>
 
 
 /* Constant that identifies the `devpts' filesystem.  */
 /* Constant that identifies the `devpts' filesystem.  */
@@ -34,18 +39,21 @@ int __unix_grantpt (int fd);
    pseudo terminal in a safe way.  */
    pseudo terminal in a safe way.  */
 static int pts_name (int fd, char **pts, size_t buf_len);
 static int pts_name (int fd, char **pts, size_t buf_len);
 
 
+#endif
+
 /* Change the ownership and access permission of the slave pseudo
 /* Change the ownership and access permission of the slave pseudo
    terminal associated with the master pseudo terminal specified
    terminal associated with the master pseudo terminal specified
    by FD.  */
    by FD.  */
 int
 int
 grantpt (int fd)
 grantpt (int fd)
 {
 {
+#if !defined ASSUME_DEVPTS
   struct statfs fsbuf;
   struct statfs fsbuf;
-#ifdef PATH_MAX
+# ifdef PATH_MAX
   char _buf[PATH_MAX];
   char _buf[PATH_MAX];
-#else
+# else
   char _buf[512];
   char _buf[512];
-#endif
+# endif
   char *buf = _buf;
   char *buf = _buf;
 
 
   if (pts_name (fd, &buf, sizeof (_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
   /* If the slave pseudo terminal lives on a `devpts' filesystem, the
      ownership and access permission are already set.  */
      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);
   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

+ 36 - 17
libc/stdlib/ptsname.c

@@ -27,6 +27,8 @@
 #include <termios.h>
 #include <termios.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
+#if !defined UNIX98PTY_ONLY
+
 /* Check if DEV corresponds to a master pseudo terminal device.  */
 /* Check if DEV corresponds to a master pseudo terminal device.  */
 #define MASTER_P(Dev)                                                         \
 #define MASTER_P(Dev)                                                         \
   (major ((Dev)) == 2                                                         \
   (major ((Dev)) == 2                                                         \
@@ -44,22 +46,16 @@
    supported.  They have been replaced by major numbers 2 (masters)
    supported.  They have been replaced by major numbers 2 (masters)
    and 3 (slaves).  */
    and 3 (slaves).  */
      
      
-/* Directory where we can find the slave pty nodes.  */
-#define _PATH_DEVPTS "/dev/pts/"
-
 /* The are declared in getpt.c.  */
 /* The are declared in getpt.c.  */
 extern const char _ptyname1[];
 extern const char _ptyname1[];
 extern const char _ptyname2[];
 extern const char _ptyname2[];
 
 
-/* Static buffer for `ptsname'.  */
-static char buffer[sizeof (_PATH_DEVPTS) + 20];
+#endif
 
 
-/*
-extern char * 
-_itoa_word (unsigned long value, char *buflim,
-	unsigned int base, int upper_case);
-*/
+/* Directory where we can find the slave pty nodes.  */
+#define _PATH_DEVPTS "/dev/pts/"
 
 
+extern char *__ultostr(char *buf, unsigned long uval, int base, int uppercase);
 
 
 /* Store at most BUFLEN characters of the pathname of the slave pseudo
 /* Store at most BUFLEN characters of the pathname of the slave pseudo
    terminal associated with the master FD is open on in BUF.
    terminal associated with the master FD is open on in BUF.
@@ -67,7 +63,9 @@ _itoa_word (unsigned long value, char *buflim,
 int ptsname_r (int fd, char *buf, size_t buflen)
 int ptsname_r (int fd, char *buf, size_t buflen)
 {
 {
   int save_errno = errno;
   int save_errno = errno;
+#if !defined UNIX98PTY_ONLY
   struct stat st;
   struct stat st;
+#endif
   int ptyno;
   int ptyno;
 
 
   if (buf == NULL)
   if (buf == NULL)
@@ -76,26 +74,28 @@ int ptsname_r (int fd, char *buf, size_t buflen)
       return EINVAL;
       return EINVAL;
     }
     }
 
 
+#if !defined UNIX98PTY_ONLY
   if (!isatty (fd))
   if (!isatty (fd))
     {
     {
       errno = ENOTTY;
       errno = ENOTTY;
       return ENOTTY;
       return ENOTTY;
     }
     }
-#if 0
+#elif !defined TIOCGPTN
+# error "UNIX98PTY_ONLY requested but TIOCGPTN is undefined."
+#endif
 #ifdef TIOCGPTN
 #ifdef TIOCGPTN
   if (ioctl (fd, TIOCGPTN, &ptyno) == 0)
   if (ioctl (fd, TIOCGPTN, &ptyno) == 0)
     {
     {
       /* Buffer we use to print the number in.  For a maximum size for
       /* Buffer we use to print the number in.  For a maximum size for
          `int' of 8 bytes we never need more than 20 digits.  */
          `int' of 8 bytes we never need more than 20 digits.  */
       char numbuf[21];
       char numbuf[21];
-      const char *devpts = _PATH_DEVPTS;
-      const size_t devptslen = strlen (devpts);
+      static const char devpts[] = _PATH_DEVPTS;
       char *p;
       char *p;
 
 
       numbuf[20] = '\0';
       numbuf[20] = '\0';
-      p = _itoa_word (ptyno, &numbuf[20], 10, 0);
+      p = __ultostr (&numbuf[sizeof numbuf - 1], ptyno, 10, 0);
 
 
-      if (buflen < devptslen + strlen (p) + 1)
+      if (buflen < sizeof devpts + &numbuf[sizeof numbuf - 1] - p)
 	{
 	{
 	  errno = ERANGE;
 	  errno = ERANGE;
 	  return ERANGE;
 	  return ERANGE;
@@ -104,9 +104,25 @@ int ptsname_r (int fd, char *buf, size_t buflen)
       strcpy (buf, devpts);
       strcpy (buf, devpts);
       strcat (buf, p);
       strcat (buf, p);
     }
     }
-  else if (errno == EINVAL)
-#endif
 #endif
 #endif
+#if defined UNIX98PTY_ONLY
+  else
+    {
+      /* If the ioctl fails it wasn't a Unix 98 master PTY */
+      errno = ENOTTY;
+      return ENOTTY;
+    }
+  /* Note: Don't bother with stat on the slave name and checking the
+           driver's major device number - the ioctl above succeeded so
+           we know the fd was a Unix'98 master and the /dev/pts/ prefix
+           is set by definition.  If the name isn't really a slave PTY,
+           the system is misconfigured anyway - something else will fail
+           later.
+   */
+#else
+# if !defined TIOCGPTN
+  else if (errno == EINVAL)
+# endif
     {
     {
       char *p;
       char *p;
 
 
@@ -156,6 +172,7 @@ int ptsname_r (int fd, char *buf, size_t buflen)
       errno = ENOTTY;
       errno = ENOTTY;
       return ENOTTY;
       return ENOTTY;
     }
     }
+#endif
 
 
   errno = save_errno;
   errno = save_errno;
   return 0;
   return 0;
@@ -167,5 +184,7 @@ int ptsname_r (int fd, char *buf, size_t buflen)
 char *
 char *
 ptsname (int fd)
 ptsname (int fd)
 {
 {
+  static char buffer[sizeof (_PATH_DEVPTS) + 20];
+
   return ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
   return ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
 }
 }

+ 19 - 1
libutil/openpty.c

@@ -32,6 +32,8 @@ extern int grantpt (int fd);
 extern int ptsname_r (int fd, char *buf, size_t buflen);
 extern int ptsname_r (int fd, char *buf, size_t buflen);
 extern int unlockpt (int fd);
 extern int unlockpt (int fd);
 
 
+/* BCS: the following function is, IMO, overkill */
+#if 0
 /* Return the result of ptsname_r in the buffer pointed to by PTS,
 /* Return the result of ptsname_r in the buffer pointed to by PTS,
    which should be of length BUF_LEN.  If it is too long to fit in
    which should be of length BUF_LEN.  If it is too long to fit in
    this buffer, a sufficiently long buffer is allocated using malloc,
    this buffer, a sufficiently long buffer is allocated using malloc,
@@ -83,6 +85,7 @@ pts_name (int fd, char **pts, size_t buf_len)
 
 
   return rv;
   return rv;
 }
 }
+#endif
 
 
 /* Create pseudo tty master slave pair and set terminal attributes
 /* Create pseudo tty master slave pair and set terminal attributes
    according to TERMP and WINP.  Return handles for both ends in
    according to TERMP and WINP.  Return handles for both ends in
@@ -91,12 +94,20 @@ int
 openpty (int *amaster, int *aslave, char *name, struct termios *termp,
 openpty (int *amaster, int *aslave, char *name, struct termios *termp,
 	 struct winsize *winp)
 	 struct winsize *winp)
 {
 {
+#if 0
 #ifdef PATH_MAX
 #ifdef PATH_MAX
   char _buf[PATH_MAX];
   char _buf[PATH_MAX];
 #else
 #else
   char _buf[512];
   char _buf[512];
 #endif
 #endif
   char *buf = _buf;
   char *buf = _buf;
+#else
+#ifdef PATH_MAX
+  char buf[PATH_MAX];
+#else
+  char buf[512];
+#endif
+#endif
   int master, slave;
   int master, slave;
 
 
   master = getpt ();
   master = getpt ();
@@ -109,15 +120,20 @@ openpty (int *amaster, int *aslave, char *name, struct termios *termp,
   if (unlockpt (master))
   if (unlockpt (master))
     goto fail;
     goto fail;
 
 
+#if 0
   if (pts_name (master, &buf, sizeof (_buf)))
   if (pts_name (master, &buf, sizeof (_buf)))
+#else
+  if (ptsname_r (master, buf, sizeof buf))
+#endif
     goto fail;
     goto fail;
 
 
   slave = open (buf, O_RDWR | O_NOCTTY);
   slave = open (buf, O_RDWR | O_NOCTTY);
   if (slave == -1)
   if (slave == -1)
     {
     {
+#if 0
       if (buf != _buf)
       if (buf != _buf)
 	free (buf);
 	free (buf);
-
+#endif
       goto fail;
       goto fail;
     }
     }
 
 
@@ -132,8 +148,10 @@ openpty (int *amaster, int *aslave, char *name, struct termios *termp,
   if (name != NULL)
   if (name != NULL)
     strcpy (name, buf);
     strcpy (name, buf);
 
 
+#if 0
   if (buf != _buf)
   if (buf != _buf)
     free (buf);
     free (buf);
+#endif
   return 0;
   return 0;
 
 
  fail:
  fail: