diff mbox series

[FFmpeg-devel,1/2] configure: Check for GetStdHandle in addition to SetConsoleTextAttribute

Message ID 20200121202447.12496-1-martin@martin.st
State New
Headers show
Series [FFmpeg-devel,1/2] configure: Check for GetStdHandle in addition to SetConsoleTextAttribute
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

Martin Storsjö Jan. 21, 2020, 8:24 p.m. UTC
SetConsoleTextAttribute used to be unavailable for Windows Store apps,
but is available to them now. But GetStdHandle still is unavailable,
thus make sure to check for both functions before using code that
requires both.
---
Alternatively we could check for just GetStdHandle instead of
SetConsoleTextAttribute.
---
 configure       | 2 ++
 libavutil/log.c | 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/configure b/configure
index 1f3d0fdd4b..c02dbcc8b2 100755
--- a/configure
+++ b/configure
@@ -2201,6 +2201,7 @@  SYSTEM_FUNCS="
     GetProcessMemoryInfo
     GetProcessTimes
     getrusage
+    GetStdHandle
     GetSystemTimeAsFileTime
     gettimeofday
     glob
@@ -6040,6 +6041,7 @@  check_func_headers sys/stat.h lstat
 check_func_headers windows.h GetModuleHandle
 check_func_headers windows.h GetProcessAffinityMask
 check_func_headers windows.h GetProcessTimes
+check_func_headers windows.h GetStdHandle
 check_func_headers windows.h GetSystemTimeAsFileTime
 check_func_headers windows.h LoadLibrary
 check_func_headers windows.h MapViewOfFile
diff --git a/libavutil/log.c b/libavutil/log.c
index e8a0db7716..16197f4081 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -55,7 +55,7 @@  static int av_log_level = AV_LOG_INFO;
 static int flags;
 
 #define NB_LEVELS 8
-#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE
+#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
 #include <windows.h>
 static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = {
     [AV_LOG_PANIC  /8] = 12,
@@ -122,7 +122,7 @@  static int use_color = -1;
 
 static void check_color_terminal(void)
 {
-#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE
+#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
     CONSOLE_SCREEN_BUFFER_INFO con_info;
     con = GetStdHandle(STD_ERROR_HANDLE);
     use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") &&
@@ -157,7 +157,7 @@  static void colored_fputs(int level, int tint, const char *str)
     if (level == AV_LOG_INFO/8) local_use_color = 0;
     else                        local_use_color = use_color;
 
-#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE
+#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
     if (local_use_color)
         SetConsoleTextAttribute(con, background | color[level]);
     fputs(str, stderr);