isatty.c 260 字节
Newer Older
R
Rich Felker 已提交
1
#include <unistd.h>
2
#include <errno.h>
3 4
#include <sys/ioctl.h>
#include "syscall.h"
R
Rich Felker 已提交
5 6 7

int isatty(int fd)
{
8
	struct winsize wsz;
9 10 11 12
	unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
	if (r == 0) return 1;
	if (errno != EBADF) errno = ENOTTY;
	return 0;
R
Rich Felker 已提交
13
}