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
1ac4f8e362
commit
4ca430b6f9
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue