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.
* lib/ttyname_r.c (ttyname_r): Produce a NUL-terminated result.
# 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.
}
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))
{