Skip to content

Commit d63e351

Browse files
committed
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 cbb3f3c (mingw: intercept isatty() to handle /dev/null as Git expects it, 2016-12-11) that broke everything on Windows. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4ddde64 commit d63e351

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compat/winansi.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static void warn_if_raster_font(void)
8181
static int is_console(int fd)
8282
{
8383
CONSOLE_SCREEN_BUFFER_INFO sbi;
84+
DWORD mode;
8485
HANDLE hcon;
8586

8687
static int initialized = 0;
@@ -95,7 +96,10 @@ static int is_console(int fd)
9596
return 0;
9697

9798
/* check if its a handle to a console output screen buffer */
98-
if (!GetConsoleScreenBufferInfo(hcon, &sbi))
99+
if (!fd) {
100+
if (!GetConsoleMode(hcon, &mode))
101+
return 0;
102+
} else if (!GetConsoleScreenBufferInfo(hcon, &sbi))
99103
return 0;
100104

101105
/* initialize attributes */

0 commit comments

Comments
 (0)