diff options
author | Tamar Christina <tamar@zhox.com> | 2019-06-02 15:08:20 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2020-07-15 16:41:01 -0400 |
commit | d548a3b3058232cbfd588f6a2c2b9108bbe8d190 (patch) | |
tree | 71caa58d3a649bc8adb453e767a65700debe8b7d /rts/RtsStartup.c | |
parent | 71245fcce24723910f12f934fbc4c700658b727a (diff) | |
download | haskell-d548a3b3058232cbfd588f6a2c2b9108bbe8d190.tar.gz |
winio: Init Windows console Codepage to UTF-8.
Diffstat (limited to 'rts/RtsStartup.c')
-rw-r--r-- | rts/RtsStartup.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c index f73d0bd742..31f8267708 100644 --- a/rts/RtsStartup.c +++ b/rts/RtsStartup.c @@ -51,6 +51,7 @@ #if defined(mingw32_HOST_OS) #include <fenv.h> +#include <windows.h> #else #include "posix/TTY.h" #endif @@ -120,6 +121,21 @@ void fpreset(void) { _fpreset(); } #endif + +/* Set the console's CodePage to UTF-8 if using the new I/O manager and the CP + is still the default one. */ +static void +initConsoleCP (void) +{ + /* Check if the codepage is still the system default ANSI codepage. */ + if (GetConsoleCP () == GetOEMCP ()) { + if (! SetConsoleCP (CP_UTF8)) + errorBelch ("Unable to set console CodePage, Unicode output may be " + "garbled.\n"); + else + IF_DEBUG (scheduler, debugBelch ("Codepage set to UTF-8.\n")); + } +} #endif /* ----------------------------------------------------------------------------- @@ -220,6 +236,12 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config) #endif /* DEBUG */ } + /* Initialize console Codepage. */ +#if defined(mingw32_HOST_OS) + if (is_io_mng_native_p()) + initConsoleCP(); +#endif + /* Initialise the stats department, phase 1 */ initStats1(); |