summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2017-03-27 20:32:51 (GMT)
committerGitHub <noreply@github.com>2017-03-27 20:32:51 (GMT)
commitab547a0ef8e78a5930936b0440020bb779f1d53c (patch)
treea4c1dd6caf0dfca7b09f31a38a5dec1852dd81d5
parent84246b974e41740e0f20036f5ca06d9996a04291 (diff)
parent9b1f00056aaa8b1c4d0877d1f73c9da6c2b1e2d7 (diff)
downloadlz4-ab547a0ef8e78a5930936b0440020bb779f1d53c.zip
lz4-ab547a0ef8e78a5930936b0440020bb779f1d53c.tar.gz
lz4-ab547a0ef8e78a5930936b0440020bb779f1d53c.tar.bz2
Merge pull request #342 from iburinoc/isatty
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..66491b6 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