Skip to content

Commit fee807c

Browse files
dschogitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbb3f3c commit fee807c

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
@@ -84,6 +84,7 @@ static void warn_if_raster_font(void)
8484
static int is_console(int fd)
8585
{
8686
CONSOLE_SCREEN_BUFFER_INFO sbi;
87+
DWORD mode;
8788
HANDLE hcon;
8889

8990
static int initialized = 0;
@@ -98,7 +99,10 @@ static int is_console(int fd)
9899
return 0;
99100

100101
/* 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))
102106
return 0;
103107

104108
/* initialize attributes */

0 commit comments

Comments
 (0)