From f68069b334f95cfd6d18db4bb059b792beb48158 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 24 Jun 2012 17:05:25 +0200 Subject: ptsname_r: Fix test failures on IRIX, Solaris. * m4/ptsname_r.m4 (gl_PREREQ_PTSNAME_R): Test whether isatty sets errno when it fails. Define ISATTY_FAILS_WITHOUT_SETTING_ERRNO accordingly. * lib/ptsname_r.c: Include . (__ptsname_r): When isatty returned false, then on IRIX, Solaris set errno if fd is invalid. * tests/test-isatty.c (main): Update comments. --- lib/ptsname_r.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/ptsname_r.c') diff --git a/lib/ptsname_r.c b/lib/ptsname_r.c index f2e34100c1..aa3ba38cb0 100644 --- a/lib/ptsname_r.c +++ b/lib/ptsname_r.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -59,8 +60,16 @@ __ptsname_r (int fd, char *buf, size_t buflen) } if (!__isatty (fd)) - /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */ - return errno; + { +#if ISATTY_FAILS_WITHOUT_SETTING_ERRNO && defined F_GETFL /* IRIX, Solaris */ + /* Set errno. */ + if (fcntl (fd, F_GETFL) != -1) + errno = ENOTTY; +#else + /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */ +#endif + return errno; + } if (buflen < strlen (_PATH_TTY) + 3) { -- cgit v1.2.1