mirror of
https://github.com/NixOS/nix.git
synced 2024-11-27 17:22:29 +00:00
Fix argument order in the Windows implementation of getEnvOs
See the build failure in https://github.com/msys2/MINGW-packages/pull/22499
(cherry picked from commit 355f08a728
)
# Conflicts:
# src/libutil/windows/environment-variables.cc
This commit is contained in:
parent
ef21dfa221
commit
9fd776200b
@ -4,7 +4,34 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
<<<<<<< HEAD
|
||||
int unsetenv(const char *name)
|
||||
=======
|
||||
std::optional<OsString> getEnvOs(const OsString & key)
|
||||
{
|
||||
// Determine the required buffer size for the environment variable value
|
||||
DWORD bufferSize = GetEnvironmentVariableW(key.c_str(), nullptr, 0);
|
||||
if (bufferSize == 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Allocate a buffer to hold the environment variable value
|
||||
std::wstring value{bufferSize, L'\0'};
|
||||
|
||||
// Retrieve the environment variable value
|
||||
DWORD resultSize = GetEnvironmentVariableW(key.c_str(), &value[0], bufferSize);
|
||||
if (resultSize == 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Resize the string to remove the extra null characters
|
||||
value.resize(resultSize);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
int unsetenv(const char * name)
|
||||
>>>>>>> 355f08a72 (Fix argument order in the Windows implementation of `getEnvOs`)
|
||||
{
|
||||
return -SetEnvironmentVariableA(name, nullptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user