From msdn :
_isatty returns a nonzero value if the descriptor is associated with a character device. Otherwise, _isatty returns 0.
NUL is like / dev / null on Unix, it's a char device.
Note that on Linux isatty is different:
The isatty () function checks if fd is an open file descriptor that refers to a terminal.
What you can do is try to compare STDIN_FILENO (0) with $ {cwd} / NUL (using stat or stat).
Update:
int ret = GetFileType(GetStdHandle(STD_INPUT_HANDLE));
It will return FILE_TYPE_CHAR for NUL or tty.
See the GetFileType documentation for other values. You can detect files / char device / pipes.
Update Final:
Use GetConsoleMode for input and GetConsoleScreenBufferInfo for output.
CONSOLE_SCREEN_BUFFER_INFO sbi; DWORD mode; if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode)) fprintf(stderr, "not console\n"); else fprintf(stderr, "console\n"); if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi)) fprintf(stderr, "not console\n"); else fprintf(stderr, "console\n");
iksaif
source share