From 9a033b82181844a4ef755ab199a6ab876be74d4d Mon Sep 17 00:00:00 2001 From: bulk88 Date: Tue, 17 Jun 2025 06:31:46 -0400 Subject: [PATCH] win32_isatty() dont call a mostly failing syscall, NT->WIN err conv is slow --- win32/win32.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/win32/win32.c b/win32/win32.c index 473a6d0c62ca..a480bc8c4b94 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4000,7 +4000,10 @@ win32_isatty(int fd) return 0; } - if (GetConsoleMode(fh, &mode)) + /* Prevent executing RtlNtStatusToDosError() for disk files and sockets + inside GetConsoleMode(). RtlNtStatusToDosError() does a slow linear + search. For details, see PR for this commit.*/ + if (GetFileType(fh) == FILE_TYPE_CHAR && GetConsoleMode(fh, &mode)) return 1; errno = ENOTTY;