isatty: EINVAL or ENOTTY?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The isatty(3) man page says the function fails with EINVAL when "fd refers to a file other than a terminal. POSIX.1 specifies the error ENOTTY for this case."

But I couldn't reproduce this bug. For me, it fails with ENOTTY, as prescribed by POSIX.

I've tested this on the following systems:
* Debian unstable (Linux 4.19, glibc 2.28)
* CentOS 5.0 (Linux 2.6.16, glibc 2.5)

The source code for the test program I used is attached.

--
Jakub Wilk
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	int fd = open("/dev/null", O_RDONLY);
	if (fd < 0) {
		perror("open()");
		return 1;
	}
	int rc = isatty(fd);
	if (rc) {
		fprintf(stderr, "/dev/null is a tty?!\n");
		return 1;
	}
	switch (errno) {
	case EINVAL:
		printf("EINVAL\n");
		return 0;
	case ENOTTY:
		printf("ENOTTY\n");
		return 0;
	default:
		perror("isatty()\n");
		return 1;
	}
}

[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux