[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 <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
: "";
}

View File

@ -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