mirror of https://github.com/stella-emu/stella.git
Visual Studio doesn't support std::getenv, so we use Windows-specific
code.
This commit is contained in:
parent
4f396efb9a
commit
8c74a73f37
|
@ -249,14 +249,25 @@ namespace BSPF
|
||||||
// Coverity complains if 'getenv' is used unrestricted
|
// Coverity complains if 'getenv' is used unrestricted
|
||||||
inline string getenv(const string& env_var)
|
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 {
|
try {
|
||||||
const char* val = std::getenv(env_var.c_str());
|
const char* val = std::getenv(env_var.c_str());
|
||||||
|
|
||||||
return val ? string(val) : EmptyString;
|
return val ? string(val) : EmptyString;
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
return EmptyString;
|
return EmptyString;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} // namespace BSPF
|
} // namespace BSPF
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue