mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 03:27:12 +01:00
Rework System::get_environmental_variable()
This commit is contained in:
parent
b364239d07
commit
5f39474a17
@ -1,5 +1,6 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "vcpkg_System.h"
|
#include "vcpkg_System.h"
|
||||||
|
#include "vcpkg_Checks.h"
|
||||||
|
|
||||||
namespace vcpkg::System
|
namespace vcpkg::System
|
||||||
{
|
{
|
||||||
@ -92,15 +93,16 @@ namespace vcpkg::System
|
|||||||
|
|
||||||
optional<std::wstring> get_environmental_variable(const wchar_t* varname) noexcept
|
optional<std::wstring> get_environmental_variable(const wchar_t* varname) noexcept
|
||||||
{
|
{
|
||||||
wchar_t* buffer;
|
auto sz = GetEnvironmentVariableW(varname, nullptr, 0);
|
||||||
_wdupenv_s(&buffer, nullptr, varname);
|
if (sz == 0)
|
||||||
|
|
||||||
if (buffer == nullptr)
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
std::unique_ptr<wchar_t, void(__cdecl *)(void*)> bufptr(buffer, free);
|
auto ret = std::make_unique<std::wstring>(sz, L'\0');
|
||||||
return std::make_unique<std::wstring>(buffer);
|
Checks::check_exit(MAXDWORD >= ret->size());
|
||||||
|
auto sz2 = GetEnvironmentVariableW(varname, ret->data(), static_cast<DWORD>(ret->size()));
|
||||||
|
Checks::check_exit(sz2 + 1 == sz);
|
||||||
|
ret->pop_back();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_environmental_variable(const wchar_t* varname, const wchar_t* varvalue) noexcept
|
void set_environmental_variable(const wchar_t* varname, const wchar_t* varvalue) noexcept
|
||||||
|
Loading…
x
Reference in New Issue
Block a user