From 4a4f5bea29b3832c3bb75badaa5ed55a0edd1e08 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 8 Dec 2017 11:18:23 +0100 Subject: [PATCH] [util] Added missing files --- src/util/util_env.cpp | 22 ++++++++++++++++++++++ src/util/util_env.h | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/util/util_env.cpp create mode 100644 src/util/util_env.h diff --git a/src/util/util_env.cpp b/src/util/util_env.cpp new file mode 100644 index 00000000..4da507e3 --- /dev/null +++ b/src/util/util_env.cpp @@ -0,0 +1,22 @@ +#include "util_env.h" + +#include "./com/com_include.h" + +namespace dxvk::env { + + std::string getEnvVar(const wchar_t* name) { + DWORD len = ::GetEnvironmentVariableW(name, nullptr, 0); + + std::wstring result; + + while (len > result.size()) { + result.resize(len); + len = ::GetEnvironmentVariableW( + name, result.data(), result.size()); + } + + result.resize(len); + return str::fromws(result); + } + +} diff --git a/src/util/util_env.h b/src/util/util_env.h new file mode 100644 index 00000000..ad9cdf52 --- /dev/null +++ b/src/util/util_env.h @@ -0,0 +1,18 @@ +#pragma once + +#include "util_string.h" + +namespace dxvk::env { + + /** + * \brief Gets environment variable + * + * If the variable is not defined, this will return + * an empty string. Note that environment variables + * may be defined with an empty value. + * \param [in] name Name of the variable + * \returns Value of the variable + */ + std::string getEnvVar(const wchar_t* name); + +} \ No newline at end of file