From fb388657c8cdabbb8feda46a05b015f87bb7d7e2 Mon Sep 17 00:00:00 2001 From: Kenichi Maruyama <25722430+kemaruya@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:51:09 +0900 Subject: [PATCH] Update win32-utf8.c I implemented a workaround for the #2027 issue. --- contrib/win32/win32compat/win32-utf8.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/contrib/win32/win32compat/win32-utf8.c b/contrib/win32/win32compat/win32-utf8.c index dd104130f..cef67337b 100644 --- a/contrib/win32/win32compat/win32-utf8.c +++ b/contrib/win32/win32compat/win32-utf8.c @@ -7,6 +7,11 @@ #include "console.h" +// previous codepage +UINT g_previous_codepage = 0; + +void +mresetlocale(void); int vfmprintf(FILE *stream, const char *fmt, va_list ap) @@ -96,6 +101,18 @@ void msetlocale(void) { // allow console output of unicode characters - SetConsoleOutputCP(CP_UTF8); + g_previous_codepage = SetConsoleOutputCP(CP_UTF8); + + // register reset function at exit + atexit(mresetlocale); } +void +mresetlocale(void) +{ + if( 0 != g_previous_codepage ) + { + // restore console output codepage for previous one + SetConsoleOutputCP(g_previous_codepage); + } +} \ No newline at end of file