From d041bda5cfb1df50833e35c376c62c5a14bb31c2 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 15 Mar 2021 17:22:45 +0100 Subject: [PATCH] (Windows) Fixed two MSVC compiler warnings. --- es-core/src/Platform.cpp | 3 ++- es-core/src/utils/FileSystemUtil.cpp | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/es-core/src/Platform.cpp b/es-core/src/Platform.cpp index 5e26319d3..90134a0a9 100644 --- a/es-core/src/Platform.cpp +++ b/es-core/src/Platform.cpp @@ -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 diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index f2cd8ffb8..2790c1bb8 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -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.