1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmCLocaleEnvironmentScope.h"
8 #include "cmSystemTools.h"
10 cmCLocaleEnvironmentScope::cmCLocaleEnvironmentScope()
12 this->SetEnv("LANGUAGE", "");
13 this->SetEnv("LC_MESSAGES", "C");
15 std::string lcAll = this->GetEnv("LC_ALL");
18 this->SetEnv("LC_ALL", "");
19 this->SetEnv("LC_CTYPE", lcAll);
23 std::string cmCLocaleEnvironmentScope::GetEnv(std::string const& key)
26 cmSystemTools::GetEnv(key, value);
30 void cmCLocaleEnvironmentScope::SetEnv(std::string const& key,
31 std::string const& value)
33 std::string oldValue = this->GetEnv(key);
35 this->EnvironmentBackup.insert(std::make_pair(key, oldValue));
38 cmSystemTools::UnsetEnv(key.c_str());
40 std::ostringstream tmp;
41 tmp << key << "=" << value;
42 cmSystemTools::PutEnv(tmp.str());
46 cmCLocaleEnvironmentScope::~cmCLocaleEnvironmentScope()
48 for (auto const& envb : this->EnvironmentBackup) {
49 std::ostringstream tmp;
50 tmp << envb.first << "=" << envb.second;
51 cmSystemTools::PutEnv(tmp.str());