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_ARCH_SAVE_REGS;
- return (GetFileType (handle) == FILE_TYPE_CHAR);
+ DWORD mode;
+ return GetConsoleMode (handle, &mode) != 0;
}
MonoBoolean