summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Purcell <me@seanp.xyz>2017-03-27 12:10:10 -0700
committerSean Purcell <me@seanp.xyz>2017-03-27 12:10:10 -0700
commitafde27acf29389fe22cee4da07eafbfc4ebaf3ed (patch)
tree3ff1f979acb300283f820be8aa4b7483c43c4200
parent84246b974e41740e0f20036f5ca06d9996a04291 (diff)
downloadlz4-afde27acf29389fe22cee4da07eafbfc4ebaf3ed.tar.gz
lz4-afde27acf29389fe22cee4da07eafbfc4ebaf3ed.tar.bz2
lz4-afde27acf29389fe22cee4da07eafbfc4ebaf3ed.zip
Fix IS_CONSOLE returning 1 for NUL on windows
-rw-r--r--programs/platform.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/programs/platform.h b/programs/platform.h
index 51ce1ac..1238140 100644
--- a/programs/platform.h
+++ b/programs/platform.h
@@ -108,9 +108,18 @@ extern "C" {
#if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 1)) || (PLATFORM_POSIX_VERSION >= 200112L) || defined(__DJGPP__)
# include <unistd.h> /* 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 <io.h> /* _isatty */
# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
+#elif defined(WIN32) || defined(_WIN32)
+# include <io.h> /* _isatty */
+# include <windows.h> /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */
+# include <stdio.h> /* 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