From d46c27a98eb3a11b60fdf76107ab96487d747ef2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 24 Jun 2012 23:28:13 +0200 Subject: [PATCH] ptsname_r: Make it consistent with ptsname on OSF/1. * lib/ptsname_r.c (__ptsname_r): Add a different implementation for OSF/1. --- ChangeLog | 6 ++++++ lib/ptsname_r.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/ChangeLog b/ChangeLog index 94e8a4148..908dca4d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2012-06-24 Bruno Haible + 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 + ttyname_r: Fix result on OSF/1, Solaris. * lib/ttyname_r.c (ttyname_r): Produce a NUL-terminated result. diff --git a/lib/ptsname_r.c b/lib/ptsname_r.c index 3805347c7..ec314c6b4 100644 --- a/lib/ptsname_r.c +++ b/lib/ptsname_r.c @@ -53,6 +53,14 @@ # include #endif +#ifdef __osf__ +/* Get ioctl(), ISPTM. */ +# include +/* Get the major, minor macros. */ +# include +# include +#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 @@ __ptsname_r (int fd, char *buf, size_t buflen) } 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)) { -- 2.11.0