616a71dd23
Revert "Fix environment block creation (#7401)" This reverts commit7886f16714
. (cherry picked from commite46ba65665
) Revert "Always create a new environment block before we spawn a process (#7243)" This reverts commit849243af99
. References #7418 (cherry picked from commit4204d2535c
) (cherry picked from commitf8e8572c23
) (cherry picked from commitcb4c4f7b73
) (cherry picked from commitafb0cac3e3
) (cherry picked from commitb25dc74a1d
)
32 lines
1.3 KiB
C++
32 lines
1.3 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
namespace Microsoft::Console::Utils
|
|
{
|
|
//
|
|
// A case-insensitive wide-character map is used to store environment variables
|
|
// due to documented requirements:
|
|
//
|
|
// "All strings in the environment block must be sorted alphabetically by name.
|
|
// The sort is case-insensitive, Unicode order, without regard to locale.
|
|
// Because the equal sign is a separator, it must not be used in the name of
|
|
// an environment variable."
|
|
// https://docs.microsoft.com/en-us/windows/desktop/ProcThread/changing-environment-variables
|
|
//
|
|
struct WStringCaseInsensitiveCompare
|
|
{
|
|
[[nodiscard]] bool operator()(const std::wstring& lhs, const std::wstring& rhs) const noexcept
|
|
{
|
|
return (::_wcsicmp(lhs.c_str(), rhs.c_str()) < 0);
|
|
}
|
|
};
|
|
|
|
using EnvironmentVariableMapW = std::map<std::wstring, std::wstring, WStringCaseInsensitiveCompare>;
|
|
|
|
[[nodiscard]] HRESULT UpdateEnvironmentMapW(EnvironmentVariableMapW& map) noexcept;
|
|
|
|
[[nodiscard]] HRESULT EnvironmentMapToEnvironmentStringsW(EnvironmentVariableMapW& map,
|
|
std::vector<wchar_t>& newEnvVars) noexcept;
|
|
|
|
};
|