mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-11 10:24:10 +01:00
[util] Change getEnvVar to use getenv (#859)
This commit is contained in:
parent
ddce33692c
commit
7306c3153c
@ -1,29 +1,16 @@
|
||||
#include "util_env.h"
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "./com/com_include.h"
|
||||
|
||||
namespace dxvk::env {
|
||||
|
||||
std::string getEnvVar(const std::string& name) {
|
||||
int nameLen = ::MultiByteToWideChar(CP_ACP, 0, name.c_str(), name.length() + 1, nullptr, 0);
|
||||
|
||||
std::vector<WCHAR> wideName(nameLen);
|
||||
|
||||
::MultiByteToWideChar(CP_ACP, 0, name.c_str(), name.length() + 1, wideName.data(), nameLen);
|
||||
|
||||
DWORD len = ::GetEnvironmentVariableW(wideName.data(), nullptr, 0);
|
||||
|
||||
std::vector<WCHAR> result;
|
||||
|
||||
while (len > result.size()) {
|
||||
result.resize(len);
|
||||
len = ::GetEnvironmentVariableW(
|
||||
wideName.data(), result.data(), result.size());
|
||||
}
|
||||
|
||||
result.resize(len);
|
||||
return str::fromws(result.data());
|
||||
std::string getEnvVar(const char* name) {
|
||||
char* result = std::getenv(name);
|
||||
return (result)
|
||||
? result
|
||||
: "";
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace dxvk::env {
|
||||
* \param [in] name Name of the variable
|
||||
* \returns Value of the variable
|
||||
*/
|
||||
std::string getEnvVar(const std::string& name);
|
||||
std::string getEnvVar(const char* name);
|
||||
|
||||
/**
|
||||
* \brief Gets the executable name
|
||||
|
Loading…
Reference in New Issue
Block a user