Skip to content

Commit 29ad502

Browse files
authored
Merge pull request #666 from kemaruya/latestw_all
It is a workaround to address the #2027 issue.
2 parents e9b1317 + f01eb59 commit 29ad502

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

contrib/win32/win32compat/win32-utf8.c

Lines changed: 20 additions & 0 deletions
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+
mrestorelocale(void);
1015

1116
int
1217
vfmprintf(FILE *stream, const char *fmt, va_list ap)
@@ -95,7 +100,22 @@ asmprintf(char **outp, size_t sz, int *written, const char *fmt, ...)
95100
void
96101
msetlocale(void)
97102
{
103+
// save previous codepage
104+
g_previous_codepage = GetConsoleOutputCP();
105+
98106
// allow console output of unicode characters
99107
SetConsoleOutputCP(CP_UTF8);
108+
109+
// register a restore function at exit
110+
atexit(mrestorelocale);
100111
}
101112

113+
void
114+
mrestorelocale(void)
115+
{
116+
if( 0 != g_previous_codepage )
117+
{
118+
// restore console output codepage to previous one
119+
SetConsoleOutputCP(g_previous_codepage);
120+
}
121+
}

0 commit comments

Comments
 (0)