init: Change fallback locale to C.UTF-8

Much of our code assumes UTF-8 support, and this is a more realistic
guess for modern systems anyway than the default character set (which
would be ASCII only). So change the assumed fallback locale (if no
locale is defined by the user or OS) to `C.UTF-8`.

Github-Pull: #17085
Rebased-From: facb9a1315f97489a20eb0e969fdb14b5128ed2f
This commit is contained in:
Wladimir J. van der Laan 2019-10-09 14:53:18 +02:00 committed by fanquake
parent 3834d3d121
commit ba46f39418
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -1153,12 +1153,12 @@ void SetupEnvironment()
} }
#endif #endif
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
// may be invalid, in which case the "C" locale is used as fallback. // may be invalid, in which case the "C.UTF-8" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
try { try {
std::locale(""); // Raises a runtime error if current locale is invalid std::locale(""); // Raises a runtime error if current locale is invalid
} catch (const std::runtime_error&) { } catch (const std::runtime_error&) {
setenv("LC_ALL", "C", 1); setenv("LC_ALL", "C.UTF-8", 1);
} }
#elif defined(WIN32) #elif defined(WIN32)
// Set the default input/output charset is utf-8 // Set the default input/output charset is utf-8