diff --git a/src/base/kernel/Env.cpp b/src/base/kernel/Env.cpp index fd95270de..0be0480e8 100644 --- a/src/base/kernel/Env.cpp +++ b/src/base/kernel/Env.cpp @@ -24,6 +24,8 @@ #include "base/kernel/Env.h" +#include "base/kernel/Process.h" +#include "version.h" #include @@ -44,6 +46,23 @@ #endif +namespace xmrig { + + +static std::map variables; + + +static void createVariables() +{ + variables.insert({ "XMRIG_VERSION", APP_VERSION }); + variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") }); + variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") }); +} + + +} // namespace xmrig + + xmrig::String xmrig::Env::expand(const char *in) { if (in == nullptr) { @@ -86,8 +105,16 @@ xmrig::String xmrig::Env::expand(const char *in) } -xmrig::String xmrig::Env::get(const char *name) +xmrig::String xmrig::Env::get(const String &name) { + if (variables.empty()) { + createVariables(); + } + + if (variables.count(name)) { + return variables.at(name); + } + return static_cast(getenv(name)); } diff --git a/src/base/kernel/Env.h b/src/base/kernel/Env.h index 449376b67..2f33abf94 100644 --- a/src/base/kernel/Env.h +++ b/src/base/kernel/Env.h @@ -36,7 +36,7 @@ class Env { public: static String expand(const char *in); - static String get(const char *name); + static String get(const String &name); static String hostname(); };