} 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);
jv program_arguments = jv_array();
#ifdef WIN32
- SetConsoleOutputCP(CP_UTF8);
fflush(stdout);
fflush(stderr);
_setmode(fileno(stdout), _O_TEXT | _O_U8TEXT);