diff options
author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2016-04-01 14:53:38 +0900 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2017-02-25 18:51:04 -0600 |
commit | 5d058fa416a26593e411bc10c391262b9dc5e9fa (patch) | |
tree | e6f7c88942ae3bfdd6403c2a8967ee33656216ab | |
parent | 12c60b2f3203a7009d35cba0e135e40419f2ea03 (diff) |
Don't call SetConsoleOutputCP
Should use wide-string function instead of SetConsoleOutputCP.
Fixes #1121
-rw-r--r-- | src/jv_print.c | 17 | ||||
-rw-r--r-- | src/main.c | 1 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/jv_print.c b/src/jv_print.c index ce4a59af..cb2824d2 100644 --- a/src/jv_print.c +++ b/src/jv_print.c @@ -37,9 +37,20 @@ static void put_buf(const char *s, int len, FILE *fout, jv *strout, int is_tty) } else { #ifdef WIN32 /* See util.h */ - if (is_tty) - WriteFile((HANDLE)_get_osfhandle(fileno(fout)), s, len, NULL, NULL); - else + if (is_tty) { + wchar_t *ws; + 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); #else fwrite(s, 1, len, fout); @@ -203,7 +203,6 @@ int main(int argc, char* argv[]) { jv program_arguments = jv_array(); #ifdef WIN32 - SetConsoleOutputCP(CP_UTF8); fflush(stdout); fflush(stderr); _setmode(fileno(stdout), _O_TEXT | _O_U8TEXT); |