Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix argument order in the Windows implementation of getEnvOs (backport #11855) #11857

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/libutil/windows/environment-variables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading