Skip to content

Commit fb38865

Browse files
committed
Update win32-utf8.c
I implemented a workaround for the #2027 issue.
1 parent e9b1317 commit fb38865

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

contrib/win32/win32compat/win32-utf8.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
#include "console.h"
99

10+
// previous codepage
11+
UINT g_previous_codepage = 0;
12+
13+
void
14+
mresetlocale(void);
1015

1116
int
1217
vfmprintf(FILE *stream, const char *fmt, va_list ap)
@@ -96,6 +101,18 @@ void
96101
msetlocale(void)
97102
{
98103
// allow console output of unicode characters
99-
SetConsoleOutputCP(CP_UTF8);
104+
g_previous_codepage = SetConsoleOutputCP(CP_UTF8);
105+
106+
// register reset function at exit
107+
atexit(mresetlocale);
100108
}
101109

110+
void
111+
mresetlocale(void)
112+
{
113+
if( 0 != g_previous_codepage )
114+
{
115+
// restore console output codepage for previous one
116+
SetConsoleOutputCP(g_previous_codepage);
117+
}
118+
}

0 commit comments

Comments
 (0)