#ifdef HAVE_CONFIG_H #include #endif #include #include "../internal/syscall.h" /* * isatty: report whether fildes is associated with a terminal. * * The probe is the kernel's own: issue the TCGETS ioctl, which a real * terminal answers with 0 and everything else rejects with -ENOTTY (a * regular file, directory, pipe, socket, or a character device that is * not a terminal such as /dev/null). A char-device fstat check is NOT * sufficient — /dev/null is a character device but not a tty — so the * ioctl is the correct test. * * The result is derived from the raw syscall return (negative -errno on * failure), so isatty never writes errno: POSIX permits an errno set on * a 0 return but does not require one, and skipping the write keeps the * probe free of thread-local side effects. */ int isatty(int fildes) { struct termios t; return __syscall3(SYS_ioctl, fildes, 0x5401 /* TCGETS */, (long)&t) == 0 ? 1 : 0; }