Add extra variables.

This commit is contained in:
XMRig 2019-12-23 00:28:57 +07:00
parent 2d15c10e0f
commit f9d07229b4
No known key found for this signature in database
GPG key ID: 446A53638BE94409
2 changed files with 29 additions and 2 deletions

View file

@ -24,6 +24,8 @@
#include "base/kernel/Env.h" #include "base/kernel/Env.h"
#include "base/kernel/Process.h"
#include "version.h"
#include <regex> #include <regex>
@ -44,6 +46,23 @@
#endif #endif
namespace xmrig {
static std::map<String, String> 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) xmrig::String xmrig::Env::expand(const char *in)
{ {
if (in == nullptr) { 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<const char *>(getenv(name)); return static_cast<const char *>(getenv(name));
} }

View file

@ -36,7 +36,7 @@ class Env
{ {
public: public:
static String expand(const char *in); static String expand(const char *in);
static String get(const char *name); static String get(const String &name);
static String hostname(); static String hostname();
}; };