Skip to content

Commit ba0fa0d

Browse files
committed
Initialization: set fallback locale as environment variable
The scope of `std::locale::global` appears to be smaller than `setenv("LC_ALL", ...)` and insufficient to fix messed up locale settings for the whole application.
1 parent 8e4fd0c commit ba0fa0d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/util.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,18 +723,19 @@ void RenameThread(const char* name)
723723

724724
void SetupEnvironment()
725725
{
726+
std::locale loc("C");
726727
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
727728
// may be invalid, in which case the "C" locale is used as fallback.
728729
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
729730
try {
730-
std::locale(""); // Raises a runtime error if current locale is invalid
731+
loc = std::locale(""); // Raises a runtime error if current locale is invalid
731732
} catch (const std::runtime_error&) {
732-
std::locale::global(std::locale("C"));
733+
setenv("LC_ALL", "C", 1);
733734
}
734735
#endif
735736
// The path locale is lazy initialized and to avoid deinitialization errors
736737
// in multithreading environments, it is set explicitly by the main thread.
737-
boost::filesystem::path::imbue(std::locale());
738+
boost::filesystem::path::imbue(loc);
738739
}
739740

740741
void SetThreadPriority(int nPriority)

0 commit comments

Comments
 (0)