Replaced getenv usage with safer osg::getEnvVar

This commit is contained in:
Robert Osfield
2017-11-02 10:43:41 +00:00
parent aa744edacc
commit ce69f18ec7
3 changed files with 36 additions and 32 deletions

View File

@@ -17,6 +17,7 @@
#include <osg/ApplicationUsage>
#include <osg/Object>
#include <osg/Math>
#include <osg/EnvVar>
#include <osg/ref_ptr>
#include <sstream>
@@ -317,10 +318,16 @@ void ApplicationUsage::writeEnvironmentSettings(std::ostream& output)
std::string::size_type len = citr->first.find_first_of("\n\r\t ");
if (len == std::string::npos) len = citr->first.size();
line.replace(optionPos,len,citr->first.substr(0,len));
const char *cp = getenv(citr->first.substr(0, len).c_str());
if (!cp) cp = "[not set]";
else if (!*cp) cp = "[set]";
line += std::string(cp) + "\n";
std::string value;
if (getEnvVar(citr->first.substr(0, len).c_str(), value))
{
line += "[set]\n";
}
else
{
line += "[not set]\n";
}
output << line;
}