#include <stdlib.h>
#include <errno.h>
+#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
}
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)
{