Improve detecting if a handle is a console on Windows.
authorGreg Najda <LHCGreg@server.fake>
Sat, 6 Jul 2013 04:54:02 +0000 (00:54 -0400)
committerGreg Najda <LHCGreg@server.fake>
Sat, 6 Jul 2013 05:10:13 +0000 (01:10 -0400)
Use GetConsoleMode. If it succeeds (returns non-zero) then the handle is a
console. If it fails (returns zero) then the handle is not a console.

The old check, (GetFileType (handle) == FILE_TYPE_CHAR) assumes that a handle
of type FILE_TYPE_CHAR is a console. This falsely reports a handle directed to
NUL as a console.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=12752

mono/metadata/console-win32.c

index 6b940f3edfb4e85920a526d0cc56a6fa868e273f..7e0d598a2820635795a691bd69ca99f0869e5264 100644 (file)
@@ -46,7 +46,8 @@ ves_icall_System_ConsoleDriver_Isatty (HANDLE handle)
 {
        MONO_ARCH_SAVE_REGS;
 
-       return (GetFileType (handle) == FILE_TYPE_CHAR);
+       DWORD mode;
+       return GetConsoleMode (handle, &mode) != 0;
 }
 
 MonoBoolean