mingw: adjust is_console() to work with stdin

When determining whether a handle corresponds to a *real* Win32 Console (as opposed to, say, a character device such as /dev/null), we use the GetConsoleOutputBufferInfo() function as a tell-tale. However, that does not work for *input* handles associated with a console. Let's just use the GetConsoleMode() function for input handles, and since it does not work on output handles fall back to the previous method for those. This patch prepares for using is_console() instead of my previous misguided attempt in cbb3f3c9b1 (mingw: intercept isatty() to handle /dev/null as Git expects it, 2016-12-11) that broke everything on Windows. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 22, 2016 at 18:08 UTC fee807c5f6da43ba03f4f92d832fd625ab57b0d7
1 file changed +5 -1
compat/winansi.c
+5 -1
@@ -84,6 +84,7 @@ static void warn_if_raster_font(void)
84 static int is_console(int fd)
85 {
86 CONSOLE_SCREEN_BUFFER_INFO sbi;
87 + DWORD mode;
88 HANDLE hcon;
89
90 static int initialized = 0;
@@ -98,7 +99,10 @@ static int is_console(int fd)
99 return 0;
100
101 /* check if its a handle to a console output screen buffer */
101 - if (!GetConsoleScreenBufferInfo(hcon, &sbi))
102 + if (!fd) {
103 + if (!GetConsoleMode(hcon, &mode))
104 + return 0;
105 + } else if (!GetConsoleScreenBufferInfo(hcon, &sbi))
106 return 0;
107
108 /* initialize attributes */