Visual Studio doesn't support std::getenv, so we use Windows-specific

code.
This commit is contained in:
Stephen Anthony 2019-12-10 17:56:12 -03:30
parent 1ac4f8e362
commit 4ca430b6f9
1 changed files with 12 additions and 1 deletions

View File

@ -249,14 +249,25 @@ namespace BSPF
// Coverity complains if 'getenv' is used unrestricted
inline string getenv(const string& env_var)
{
#if (defined BSPF_WINDOWS || defined __WIN32__) && !defined __GNUG__
char* buf = nullptr;
size_t sz = 0;
if(_dupenv_s(&buf, &sz, env_var.c_str()) == 0 && buf != nullptr)
{
string val(buf);
free(buf);
return val;
}
return EmptyString;
#else
try {
const char* val = std::getenv(env_var.c_str());
return val ? string(val) : EmptyString;
}
catch(...) {
return EmptyString;
}
#endif
}
} // namespace BSPF