work around GetEnvironmentVariable not resetting last error

This commit is contained in:
mjk 2021-03-18 23:40:30 +00:00 committed by LAGonauta
parent fd035084de
commit 597061aed1

View file

@ -29,6 +29,7 @@ std::wstring GetEnv(const wchar_t *const variable_name)
if (not bufsize) if (not bufsize)
throw win32_error{}; throw win32_error{};
std::wstring buf(bufsize, noncharacter); std::wstring buf(bufsize, noncharacter);
::SetLastError(0);
const auto res = const auto res =
::GetEnvironmentVariableW(variable_name, buf.data(), bufsize); ::GetEnvironmentVariableW(variable_name, buf.data(), bufsize);
if (const auto e = ::GetLastError()) if (const auto e = ::GetLastError())