Don't call SetConsoleOutputCP
Should use wide-string function instead of SetConsoleOutputCP. Fixes #1121
This commit is contained in:
1 parent
12c60b2f32
commit
5d058fa416
2 files changed
+14
-4
No files matched your search
+14
-3
@@ -37,9 +37,20 @@ static void put_buf(const char *s, int len, FILE *fout, jv *strout, int is_tty)
|
|||||||
} else {
|
} else {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
/* See util.h */
|
/* See util.h */
|
||||||
if (is_tty)
|
if (is_tty) {
|
||||||
WriteFile((HANDLE)_get_osfhandle(fileno(fout)), s, len, NULL, NULL);
|
wchar_t *ws;
|
||||||
else
|
size_t wl;
|
||||||
|
if (len == -1)
|
||||||
|
len = strlen(s);
|
||||||
|
wl = MultiByteToWideChar(CP_UTF8, 0, s, len, NULL, 0);
|
||||||
|
ws = malloc((wl + 1) * sizeof(*ws));
|
||||||
|
if (!ws)
|
||||||
|
return;
|
||||||
|
wl = MultiByteToWideChar(CP_UTF8, 0, s, len, ws, wl + 1);
|
||||||
|
ws[wl] = 0;
|
||||||
|
WriteConsoleW((HANDLE)_get_osfhandle(fileno(fout)), ws, wl, NULL, NULL);
|
||||||
|
free(ws);
|
||||||
|
} else
|
||||||
fwrite(s, 1, len, fout);
|
fwrite(s, 1, len, fout);
|
||||||
#else
|
#else
|
||||||
fwrite(s, 1, len, fout);
|
fwrite(s, 1, len, fout);
|
||||||
|
|||||||
@@ -203,7 +203,6 @@ int main(int argc, char* argv[]) {
|
|||||||
jv program_arguments = jv_array();
|
jv program_arguments = jv_array();
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
_setmode(fileno(stdout), _O_TEXT | _O_U8TEXT);
|
_setmode(fileno(stdout), _O_TEXT | _O_U8TEXT);
|
||||||
|
|||||||
Reference in new issue
Block a user