about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/getpt.c13
-rw-r--r--sysdeps/unix/bsd/getpt.c17
-rw-r--r--sysdeps/unix/sysv/linux/getpt.c24
3 files changed, 47 insertions, 7 deletions
diff --git a/sysdeps/generic/getpt.c b/sysdeps/generic/getpt.c
index 4260d5fd34..2a4511c945 100644
--- a/sysdeps/generic/getpt.c
+++ b/sysdeps/generic/getpt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
 
@@ -30,5 +30,16 @@ __getpt ()
 }
 weak_alias (__getpt, getpt)
 
+/* We cannot define posix_openpt in general for BSD systems.  */
+int
+__posix_openpt (oflag)
+     int oflag;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+weak_alias (__posix_openpt, posix_openpt)
+
 stub_warning (getpt)
+stub_warning (posix_openpt)
 #include <stub-tag.h>
diff --git a/sysdeps/unix/bsd/getpt.c b/sysdeps/unix/bsd/getpt.c
index 42615ba159..6bd1804942 100644
--- a/sysdeps/unix/bsd/getpt.c
+++ b/sysdeps/unix/bsd/getpt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
 
@@ -77,3 +77,18 @@ __getpt (void)
 
 #undef __getpt
 weak_alias (__getpt, getpt)
+
+#ifndef HAVE_POSIX_OPENPT
+/* We cannot define posix_openpt in general for BSD systems.  */
+int
+__posix_openpt (oflag)
+     int oflag;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+weak_alias (__posix_openpt, posix_openpt)
+
+stub_warning (posix_openpt)
+# include <stub-tag.h>
+#endif
diff --git a/sysdeps/unix/sysv/linux/getpt.c b/sysdeps/unix/sysv/linux/getpt.c
index 3b01ef561e..30f7f30a4c 100644
--- a/sysdeps/unix/sysv/linux/getpt.c
+++ b/sysdeps/unix/sysv/linux/getpt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
 
@@ -36,14 +36,15 @@ int __bsd_getpt (void);
 
 /* Open a master pseudo terminal and return its file descriptor.  */
 int
-__getpt (void)
+__posix_openpt (oflag)
+     int oflag;
 {
   static int have_no_dev_ptmx;
   int fd;
 
   if (!have_no_dev_ptmx)
     {
-      fd = __open (_PATH_DEVPTMX, O_RDWR);
+      fd = __open (_PATH_DEVPTMX, oflag);
       if (fd != -1)
 	{
 	  struct statfs fsbuf;
@@ -54,7 +55,7 @@ __getpt (void)
 	  if (devpts_mounted
 	      || (__statfs (_PATH_DEVPTS, &fsbuf) == 0
 		  && fsbuf.f_type == DEVPTS_SUPER_MAGIC)
-	      || (__statfs (_PATH_DEV, &fsbuf) == 0	
+	      || (__statfs (_PATH_DEV, &fsbuf) == 0
 		  && fsbuf.f_type == DEVFS_SUPER_MAGIC))
 	    {
 	      /* Everything is ok.  */
@@ -76,11 +77,24 @@ __getpt (void)
 	}
     }
 
-  return __bsd_getpt ();
+  return -1;
+}
+weak_alias (__posix_openpt, posix_openpt)
+
+
+int
+__getpt (void)
+{
+  int fd = __posix_openpt (O_RDWR);
+  if (fd == -1)
+    fd = __bsd_getpt ();
+  return fd;
 }
 
+
 #define PTYNAME1 "pqrstuvwxyzabcde";
 #define PTYNAME2 "0123456789abcdef";
 
 #define __getpt __bsd_getpt
+#define HAVE_POSIX_OPENPT
 #include <sysdeps/unix/bsd/getpt.c>