changeset 16944:00ae3faf06c6

ptsname_r: Make it consistent with ptsname on OSF/1. * lib/ptsname_r.c (__ptsname_r): Add a different implementation for OSF/1.
author Bruno Haible <bruno@clisp.org>
date Sun, 24 Jun 2012 23:28:13 +0200
parents 60367726e145
children af6492941f0d
files ChangeLog lib/ptsname_r.c
diffstat 2 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-06-24  Bruno Haible  <bruno@clisp.org>
+
+	ptsname_r: Make it consistent with ptsname on OSF/1.
+	* lib/ptsname_r.c (__ptsname_r): Add a different implementation for
+	OSF/1.
+
 2012-06-24  Bruno Haible  <bruno@clisp.org>
 
 	ttyname_r: Fix result on OSF/1, Solaris.
--- a/lib/ptsname_r.c
+++ b/lib/ptsname_r.c
@@ -53,6 +53,14 @@
 # include <stdio.h>
 #endif
 
+#ifdef __osf__
+/* Get ioctl(), ISPTM.  */
+# include <sys/ioctl.h>
+/* Get the major, minor macros.  */
+# include <sys/sysmacros.h>
+# include <stdio.h>
+#endif
+
 
 /* Store at most BUFLEN characters of the pathname of the slave pseudo
    terminal associated with the master FD is open on in BUF.
@@ -107,6 +115,35 @@
       }
     memcpy (buf, tmpbuf, n + 1);
   }
+#elif defined __osf__ /* OSF/1 */
+  /* This implementation returns /dev/pts/N, like ptsname() does.
+     Whereas the generic implementation below returns /dev/ttypN.
+     Both are correct, but let's be consistent with ptsname().  */
+  if (fstat (fd, &st) < 0)
+    return errno;
+  if (!S_ISCHR (st.st_mode))
+    {
+      errno = ENOTTY;
+      return errno;
+    }
+  {
+    int dev;
+    char tmpbuf[9 + 10 + 1];
+    int n;
+    dev = ioctl (fd, ISPTM, NULL);
+    if (dev < 0)
+      {
+        errno = ENOTTY;
+        return errno;
+      }
+    n = sprintf (tmpbuf, "/dev/pts/%u", minor (dev));
+    if (n >= buflen)
+      {
+        errno = ERANGE;
+        return errno;
+      }
+    memcpy (buf, tmpbuf, n + 1);
+  }
 #else
   if (!__isatty (fd))
     {