31 #include <sys/ioctl.h>
33 #if defined(__MVS__) && !defined(IMAXBEL)
53 static int isreallyatty(
int file) {
56 rc = !ioctl(
file, TXISATTY + 0x81, NULL);
57 if (!rc && errno != EBADF)
62 #define isatty(fd) isreallyatty(fd)
71 #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
75 #elif defined(__APPLE__)
79 #elif defined(__NetBSD__)
94 static devmajor_t pts = NODEVMAJOR;
96 if (pts == NODEVMAJOR) {
97 pts = getdevmajor(
"pts", S_IFCHR);
98 if (pts == NODEVMAJOR)
103 if (fstat(fd, &sb) != 0)
107 if (!S_ISCHR(sb.st_mode))
111 if (major(sb.st_rdev) == NODEVMAJOR)
114 result = (pts == major(sb.st_rdev));
118 result = ptsname(fd) == NULL;
146 saved_flags = fcntl(fd, F_GETFL);
147 while (saved_flags == -1 && errno == EINTR);
149 if (saved_flags == -1)
151 mode = saved_flags & O_ACCMODE;
163 if (
type == UV_TTY) {
176 if (
mode != O_RDONLY)
184 if (
r < 0 &&
r != UV_EINVAL) {
206 #if defined(__APPLE__)
214 r = fcntl(fd, F_SETFL, saved_flags);
215 while (
r == -1 && errno == EINTR);
220 if (
mode != O_WRONLY)
222 if (
mode != O_RDONLY)
234 #if defined __sun || defined __MVS__
239 tio->c_iflag &= ~(IMAXBEL | IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR |
240 IGNCR | ICRNL | IXON);
241 tio->c_oflag &= ~OPOST;
242 tio->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
243 tio->c_cflag &= ~(CSIZE | PARENB);
259 if (tcgetattr(fd, &
tty->orig_termios))
276 tmp.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
277 tmp.c_oflag |= (ONLCR);
278 tmp.c_cflag |= (CS8);
279 tmp.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
289 if (tcsetattr(fd, TCSADRAIN, &
tmp))
303 while (
err == -1 && errno == EINTR);
330 if (S_ISREG(s.st_mode))
333 if (S_ISCHR(s.st_mode))
336 if (S_ISFIFO(s.st_mode))
337 return UV_NAMED_PIPE;
339 if (!S_ISSOCK(s.st_mode))
343 if (getsockopt(
file, SOL_SOCKET, SO_TYPE, &
type, &
len))
347 if (getsockname(
file, &sa, &
len))
350 if (
type == SOCK_DGRAM)
351 if (sa.sa_family == AF_INET || sa.sa_family ==
AF_INET6)
354 if (
type == SOCK_STREAM) {
355 #if defined(_AIX) || defined(__DragonFly__)
361 return UV_NAMED_PIPE;
364 if (sa.sa_family == AF_INET || sa.sa_family ==
AF_INET6)
366 if (sa.sa_family == AF_UNIX)
367 return UV_NAMED_PIPE;