diff --git a/reactos/lib/crt/io/isatty.c b/reactos/lib/crt/io/isatty.c index d54ae83dfa5..189ef81dfc2 100644 --- a/reactos/lib/crt/io/isatty.c +++ b/reactos/lib/crt/io/isatty.c @@ -1,5 +1,4 @@ -#include -#include +#include #define NDEBUG #include @@ -7,13 +6,10 @@ /* * @implemented */ -int _isatty( int fd ) +int _isatty(int fd) { - struct _stat buf; - DPRINT("_isatty(fd %d)\n", fd); - if (_fstat (fd, &buf) < 0) + HANDLE hFile = fdinfo(fd)->hFile; + if (hFile == INVALID_HANDLE_VALUE) return 0; - if (S_ISCHR (buf.st_mode)) - return 1; - return 0; + return GetFileType(hFile) == FILE_TYPE_CHAR ? 1 : 0; } diff --git a/reactos/lib/crt/io/open.c b/reactos/lib/crt/io/open.c index 83b7532c7ab..d36c3cb2b48 100644 --- a/reactos/lib/crt/io/open.c +++ b/reactos/lib/crt/io/open.c @@ -608,14 +608,20 @@ BOOL __fileno_init(void) if (fdinfo(0)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(0)->fdflags & FOPEN)) { fdinfo(0)->hFile = GetStdHandle(STD_INPUT_HANDLE); + if (fdinfo(0)->hFile == NULL) + fdinfo(0)->hFile = INVALID_HANDLE_VALUE; fdinfo(0)->fdflags = FOPEN|FTEXT; } if (fdinfo(1)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(1)->fdflags & FOPEN)) { fdinfo(1)->hFile = GetStdHandle(STD_OUTPUT_HANDLE); + if (fdinfo(1)->hFile == NULL) + fdinfo(1)->hFile = INVALID_HANDLE_VALUE; fdinfo(1)->fdflags = FOPEN|FTEXT; } if (fdinfo(2)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(2)->fdflags & FOPEN)) { fdinfo(2)->hFile = GetStdHandle(STD_ERROR_HANDLE); + if (fdinfo(2)->hFile == NULL) + fdinfo(2)->hFile = INVALID_HANDLE_VALUE; fdinfo(2)->fdflags = FOPEN|FTEXT; }