diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index ad7a0cf4c..50cbb770a 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -39,8 +39,8 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) if (_zipFile[0] == '~') { #if defined(BSPF_UNIX) || defined(BSPF_MACOS) - const string& home = BSPF::getenv("HOME"); - if (home != EmptyString) + const char* home = std::getenv("HOME"); + if (home != nullptr) _zipFile.replace(0, 1, home); #elif defined(BSPF_WINDOWS) _zipFile.replace(0, 1, myHomeFinder.getHomePath()); diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index d033272e6..10863f5ca 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -355,30 +355,6 @@ namespace BSPF return tm_snapshot; } - // 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 - } - inline bool isWhiteSpace(const char s) { const string WHITESPACES = " ,.;:+-*&/\\'"; diff --git a/src/unix/FSNodePOSIX.cxx b/src/unix/FSNodePOSIX.cxx index 3ce8aa44b..79aaec46c 100644 --- a/src/unix/FSNodePOSIX.cxx +++ b/src/unix/FSNodePOSIX.cxx @@ -37,8 +37,8 @@ FilesystemNodePOSIX::FilesystemNodePOSIX(const string& path, bool verify) // Expand '~' to the HOME environment variable if(_path[0] == '~') { - const string& home = BSPF::getenv("HOME"); - if(home != EmptyString) + const char* home = std::getenv("HOME"); + if (home != nullptr) _path.replace(0, 1, home); } // Get absolute path (only used for relative directories) @@ -78,7 +78,9 @@ void FilesystemNodePOSIX::setFlags() string FilesystemNodePOSIX::getShortPath() const { // If the path starts with the home directory, replace it with '~' - const string& home = BSPF::getenv("HOME"); + const char* env_home = std::getenv("HOME"); + const string& home = env_home != nullptr ? env_home : EmptyString; + if(home != EmptyString && BSPF::startsWithIgnoreCase(_path, home)) { string path = "~"; diff --git a/src/unix/OSystemUNIX.cxx b/src/unix/OSystemUNIX.cxx index edcd808d0..2dc62d6bf 100644 --- a/src/unix/OSystemUNIX.cxx +++ b/src/unix/OSystemUNIX.cxx @@ -26,8 +26,8 @@ void OSystemUNIX::getBaseDirectories(string& basedir, string& homedir, bool useappdir, const string& usedir) { // Use XDG_CONFIG_HOME if defined, otherwise use the default - string configDir = BSPF::getenv("XDG_CONFIG_HOME"); - if(configDir == EmptyString) configDir = "~/.config"; + const char* cfg_home = std::getenv("XDG_CONFIG_HOME"); + const string& configDir = cfg_home != nullptr ? cfg_home : "~/.config"; basedir = configDir + "/stella"; homedir = "~/";