From: Sean Purcell Date: Mon, 27 Mar 2017 19:19:30 +0000 (-0700) Subject: Fix IS_CONSOLE returning 1 for NUL on windows X-Git-Tag: v1.2.0^2~80^2~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=894bf4971374be233df7e954aabb3b19116c1ac7;p=thirdparty%2Fzstd.git Fix IS_CONSOLE returning 1 for NUL on windows --- diff --git a/programs/platform.h b/programs/platform.h index 89a9f6cd4..819bec873 100644 --- a/programs/platform.h +++ b/programs/platform.h @@ -100,9 +100,18 @@ extern "C" { #if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 1)) || (PLATFORM_POSIX_VERSION >= 200112L) || defined(__DJGPP__) # include /* isatty */ # define IS_CONSOLE(stdStream) isatty(fileno(stdStream)) -#elif defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) +#elif defined(MSDOS) || defined(OS2) || defined(__CYGWIN__) # include /* _isatty */ # define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) +#elif defined(WIN32) || defined(_WIN32) +# include /* _isatty */ +# include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ +# include /* FILE */ +static inline int IS_CONSOLE(FILE* stdStream) +{ + DWORD dummy; + return _isatty(_fileno(stdStream)) && GetConsoleMode((HANDLE)_get_osfhandle(_fileno(stdStream)), &dummy); +} #else # define IS_CONSOLE(stdStream) 0 #endif