Set console codepage to utf-8 (on Windows), and restore old one on exit

Avoid mojibake.
This commit is contained in:
Jeroen van Rijn
2026-08-16 16:16:35 +02:00
parent e62ed261c5
commit 0b7b8ba4a2
3 changed files with 72 additions and 8 deletions

View File

@@ -65,6 +65,20 @@ template <typename T> struct TypeIs64BitInteger { enum {value = false}; };
template <> struct TypeIs64BitInteger<u64> { enum {value = true}; };
template <> struct TypeIs64BitInteger<i64> { enum {value = true}; };
#if defined(GB_SYSTEM_WINDOWS)
uint32_t old_console_codepage = 0;
void set_utf8_codepage() {
old_console_codepage = GetConsoleOutputCP();
}
void restore_old_codepage() {
// Nothing we can do if this fails, so we're not asserting or anything.
SetConsoleOutputCP(old_console_codepage);
}
#else
void set_utf8_codepage() {}
void restore_old_codepage() {}
#endif
#include "unicode.cpp"