From 7c8d9db4e4ca1b0ab8a0c747c5c06c6e0bd85832 Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Tue, 13 May 2014 10:15:00 +0000 Subject: [PATCH] SetupEnvironment() - clean commit --- src/dogecoin-cli.cpp | 2 ++ src/dogecoind.cpp | 2 ++ src/qt/bitcoin.cpp | 2 ++ src/util.cpp | 17 ++++++++++++++++- src/util.h | 1 + 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/dogecoin-cli.cpp b/src/dogecoin-cli.cpp index 18c2b7212..84ea86cea 100644 --- a/src/dogecoin-cli.cpp +++ b/src/dogecoin-cli.cpp @@ -58,6 +58,8 @@ static bool AppInitRPC(int argc, char* argv[]) int main(int argc, char* argv[]) { + SetupEnvironment(); + try { if(!AppInitRPC(argc, argv)) diff --git a/src/dogecoind.cpp b/src/dogecoind.cpp index 9eee562d4..cfb3d8cb6 100644 --- a/src/dogecoind.cpp +++ b/src/dogecoind.cpp @@ -172,6 +172,8 @@ bool AppInit(int argc, char* argv[]) int main(int argc, char* argv[]) { + SetupEnvironment(); + bool fRet = false; // Connect dogecoind signal handlers diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index c738c4152..9763335bb 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -463,6 +463,8 @@ WId BitcoinApplication::getMainWinId() const #ifndef BITCOIN_QT_TEST int main(int argc, char *argv[]) { + SetupEnvironment(); + /// 1. Parse command-line options. These take precedence over anything else. // Command-line options take precedence: ParseParameters(argc, argv); diff --git a/src/util.cpp b/src/util.cpp index f8eb9a658..d2ca2f36a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1448,4 +1448,19 @@ bool ParseInt32(const std::string& str, int32_t *out) n >= std::numeric_limits::min() && n <= std::numeric_limits::max(); } - +void SetupEnvironment() +{ + #ifndef WIN32 + try + { + #if BOOST_FILESYSTEM_VERSION == 3 + boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid + #else // boost filesystem v2 + std::locale(); // Raises runtime error if current locale is invalid + #endif + } catch(std::runtime_error &e) + { + setenv("LC_ALL", "C", 1); // Force C locale + } + #endif +} diff --git a/src/util.h b/src/util.h index 63fce428b..53b263a9e 100644 --- a/src/util.h +++ b/src/util.h @@ -121,6 +121,7 @@ extern volatile bool fReopenDebugLog; void RandAddSeed(); void RandAddSeedPerfmon(); +void SetupEnvironment(); /* Return true if log accepts specified category */ bool LogAcceptCategory(const char* category);