Commit f396bf43 authored by Dāvis Mosāns's avatar Dāvis Mosāns Committed by Brad King
Browse files

SystemTools: Add HasEnv function

Some GetEnv callers only need to know whether an environment variable
exists, so provide a direct query for this.

Change-Id: Ib754cb122b53a2a7cc4801fc7198cf1d612ef6f4
parent 85920d53
......@@ -573,6 +573,22 @@ bool SystemTools::GetEnv(const std::string& key, std::string& result)
return SystemTools::GetEnv(key.c_str(), result);
}
bool SystemTools::HasEnv(const char* key)
{
#if defined(_WIN32)
const std::wstring wkey = Encoding::ToWide(key);
const wchar_t* v = _wgetenv(wkey.c_str());
#else
const char* v = getenv(key);
#endif
return v != 0;
}
bool SystemTools::HasEnv(const std::string& key)
{
return SystemTools::HasEnv(key.c_str());
}
//----------------------------------------------------------------------------
#if KWSYS_CXX_HAS_UNSETENV
......
......@@ -844,6 +844,8 @@ public:
static const char* GetEnv(const std::string& key);
static bool GetEnv(const char* key, std::string& result);
static bool GetEnv(const std::string& key, std::string& result);
static bool HasEnv(const char* key);
static bool HasEnv(const std::string& key);
/** Put a string into the environment
of the form var=value */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment