From 1ee308c75f4720ee38be8e81ff8c9ed4c52670d4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 22 Dec 2021 08:22:12 +0000 Subject: winansi: detect if running under Wine Detect if running under Wine by checking for the wine_get_version function in ntdll.dll. This is how the Wine Developer FAQ suggests doing it. If running under Wine and not otherwise configured: - use ANSI emulation; - don't use alternate screen buffer in vi/less. Explicit settings of BB_SKIP_ANSI_EMULATION and BB_ALT_BUFFER will override the Wine defaults. --- win32/winansi.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/win32/winansi.c b/win32/winansi.c index d8acb56d5..622ba1c77 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -4,6 +4,7 @@ #include "libbb.h" #include +#include "lazyload.h" #undef PACKED /* @@ -55,6 +56,13 @@ static int is_console_in(int fd) return isatty(fd) && GetStdHandle(STD_INPUT_HANDLE) != INVALID_HANDLE_VALUE; } +static int is_wine(void) +{ + DECLARE_PROC_ADDR(const char *, wine_get_version, void); + + return INIT_PROC_ADDR(ntdll.dll, wine_get_version) != NULL; +} + #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #endif @@ -69,7 +77,8 @@ int skip_ansi_emulation(int reset) if (skip < 0 || reset) { const char *var = getenv(bb_skip_ansi_emulation); - skip = var == NULL ? CONFIG_SKIP_ANSI_EMULATION_DEFAULT : atoi(var); + int dflt = is_wine() ? 0 : CONFIG_SKIP_ANSI_EMULATION_DEFAULT; + skip = var == NULL ? dflt : atoi(var); if (skip < 0 || skip > 2) skip = 0; @@ -115,7 +124,7 @@ static void use_alt_buffer(int flag) HANDLE console, h; var = getenv("BB_ALT_BUFFER"); - if (var && strcmp(var, "0") == 0) { + if (var ? strcmp(var, "0") == 0 : is_wine()) { reset_screen(); return; } -- cgit v1.2.3-55-g6feb