aboutsummaryrefslogtreecommitdiffstats
path: root/solc
diff options
context:
space:
mode:
Diffstat (limited to 'solc')
-rw-r--r--solc/main.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/solc/main.cpp b/solc/main.cpp
index eaada1c4..11facfa6 100644
--- a/solc/main.cpp
+++ b/solc/main.cpp
@@ -21,13 +21,38 @@
*/
#include "CommandLineInterface.h"
+#include <clocale>
#include <iostream>
#include <boost/exception/all.hpp>
using namespace std;
+/*
+The equivalent of setlocale(LC_ALL, ā€œCā€) is called before any user code is run.
+If the user has an invalid environment setting then it is possible for the call
+to set locale to fail, so there are only two possible actions, the first is to
+throw a runtime exception and cause the program to quit (default behaviour),
+or the second is to modify the environment to something sensible (least
+surprising behaviour).
+
+The follow code produces the least surprising behaviour. It will use the user
+specified default locale if it is valid, and if not then it will modify the
+environment the process is running in to use a sensible default. This also means
+that users do not need to install language packs for their OS.
+*/
+void setDefaultOrCLocale()
+{
+#if __unix__
+ if (!std::setlocale(LC_ALL, ""))
+ {
+ setenv("LC_ALL", "C", 1);
+ }
+#endif
+}
+
int main(int argc, char** argv)
{
+ setDefaultOrCLocale();
dev::solidity::CommandLineInterface cli;
if (!cli.parseArguments(argc, argv))
return 1;