(Windows) Fixed two MSVC compiler warnings.

This commit is contained in:
Leon Styhre 2021-03-15 17:22:45 +01:00
parent f35e3c2e65
commit d041bda5cf
2 changed files with 14 additions and 9 deletions

View file

@ -247,7 +247,8 @@ void emergencyShutdown()
void touch(const std::string& filename)
{
#if defined(_WIN64)
FILE* fp = fopen(filename.c_str(), "ab+");
FILE* fp;
fopen_s(&fp, filename.c_str(), "ab+");
if (fp != nullptr)
fclose(fp);
#else

View file

@ -147,17 +147,21 @@ namespace Utils
#if defined(_WIN64)
// On Windows we need to check HOMEDRIVE and HOMEPATH.
if (!homePath.length()) {
#if defined(_WIN64)
std::string envHomeDrive =
Utils::String::wideStringToString(_wgetenv(L"HOMEDRIVE"));
std::string envHomePath =
Utils::String::wideStringToString(_wgetenv(L"HOMEPATH"));
std::wstring envHomeDrive;
std::wstring envHomePath;
#if defined(_MSC_VER) // MSVC compiler.
wchar_t* buffer;
if (!_wdupenv_s(&buffer, nullptr, L"HOMEDRIVE"))
envHomeDrive = buffer;
if (!_wdupenv_s(&buffer, nullptr, L"HOMEPATH"))
envHomePath = buffer;
#else
std::string envHomeDrive = getenv("HOMEDRIVE");
std::string envHomePath = getenv("HOMEPATH");
envHomeDrive = _wgetenv(L"HOMEDRIVE");
envHomePath = _wgetenv(L"HOMEPATH");
#endif
if (envHomeDrive.length() && envHomePath.length())
homePath = getGenericPath(envHomeDrive + "/" + envHomePath);
homePath = getGenericPath(Utils::String::wideStringToString(envHomeDrive) +
"/" + Utils::String::wideStringToString(envHomePath));
}
#else
// Check for HOME environment variable.