From e03c638d0d0bd2ab50940bc479cb5b7ff18c9803 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 May 2024 14:10:20 +0200 Subject: Fix fdterm() mis-classification of nul on Windows with GetConsoleMode() call --- libbutl/fdstream.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx index 07cb9f2..df5b531 100644 --- a/libbutl/fdstream.cxx +++ b/libbutl/fdstream.cxx @@ -1889,7 +1889,13 @@ namespace butl throw_system_ios_failure (e); if (t == FILE_TYPE_CHAR) // Terminal. - return true; + { + // One notable special file that has this type is nul (as returned by + // fdopen_null()). So tighten this case with the GetConsoleMode() call. + // + DWORD m; + return GetConsoleMode (h, &m) != 0; + } if (t != FILE_TYPE_PIPE) // Pipe still can be a terminal (see below). return false; -- cgit v1.1