1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-21 02:52:10 +01:00

[util] Change getEnvVar to use getenv (#859)

This commit is contained in:
Entryhazard 2019-01-13 21:27:59 +01:00 committed by Philip Rebohle
parent ddce33692c
commit 7306c3153c
2 changed files with 7 additions and 20 deletions

View File

@ -1,29 +1,16 @@
#include "util_env.h" #include "util_env.h"
#include <vector> #include <vector>
#include <cstdlib>
#include "./com/com_include.h" #include "./com/com_include.h"
namespace dxvk::env { namespace dxvk::env {
std::string getEnvVar(const std::string& name) { std::string getEnvVar(const char* name) {
int nameLen = ::MultiByteToWideChar(CP_ACP, 0, name.c_str(), name.length() + 1, nullptr, 0); char* result = std::getenv(name);
return (result)
std::vector<WCHAR> wideName(nameLen); ? result
: "";
::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());
} }

View File

@ -13,7 +13,7 @@ namespace dxvk::env {
* \param [in] name Name of the variable * \param [in] name Name of the variable
* \returns Value 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 * \brief Gets the executable name