diff mbox series

[FFmpeg-devel,3/5] avutil/log: fix detecting console mode on Win32

Message ID 20200202211534.12739-3-cus@passwd.hu
State New
Headers show
Series [FFmpeg-devel,1/5] avutil/log: drop support for NO_COLOR environment variable
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Marton Balint Feb. 2, 2020, 9:15 p.m. UTC
A redirected stderr can still have a valid handle.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavutil/log.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/libavutil/log.c b/libavutil/log.c
index 64950016e8..6374050770 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -124,7 +124,10 @@  static void check_color_terminal(void)
 {
 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
     CONSOLE_SCREEN_BUFFER_INFO con_info;
+    DWORD dummy;
     con = GetStdHandle(STD_ERROR_HANDLE);
+    if (con != INVALID_HANDLE_VALUE && !GetConsoleMode(con, &dummy))
+        con = INVALID_HANDLE_VALUE;
     use_color = (con != INVALID_HANDLE_VALUE) && !getenv("AV_LOG_FORCE_NOCOLOR");
     if (use_color) {
         GetConsoleScreenBufferInfo(con, &con_info);