ENH: move PutEnv to SystemTools
This commit is contained in:
parent
d5f8020391
commit
fdff8eb300
|
@ -1606,32 +1606,6 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
|
|||
return cmsys::SystemTools::RelativePath(local, remote);
|
||||
}
|
||||
|
||||
class cmDeletingCharVector : public std::vector<char*>
|
||||
{
|
||||
public:
|
||||
~cmDeletingCharVector()
|
||||
{
|
||||
for(std::vector<char*>::iterator i = this->begin();
|
||||
i != this->end(); ++i)
|
||||
{
|
||||
delete []*i;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bool cmSystemTools::PutEnv(const char* value)
|
||||
{
|
||||
static cmDeletingCharVector localEnvironment;
|
||||
char* envVar = new char[strlen(value)+1];
|
||||
strcpy(envVar, value);
|
||||
int ret = putenv(envVar);
|
||||
// save the pointer in the static vector so that it can
|
||||
// be deleted on exit
|
||||
localEnvironment.push_back(envVar);
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
//----------------------------------------------------------------------
|
||||
bool cmSystemTools::UnsetEnv(const char* value)
|
||||
|
|
|
@ -337,10 +337,6 @@ public:
|
|||
*/
|
||||
static std::string RelativePath(const char* local, const char* remote);
|
||||
|
||||
/** Put a string into the environment
|
||||
of the form var=value */
|
||||
static bool PutEnv(const char* value);
|
||||
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
/** Remove an environment variable */
|
||||
static bool UnsetEnv(const char* value);
|
||||
|
|
|
@ -402,6 +402,33 @@ bool SystemTools::GetEnv(const char* key, kwsys_stl::string& result)
|
|||
}
|
||||
}
|
||||
|
||||
class kwsysDeletingCharVector : public kwsys_stl::vector<char*>
|
||||
{
|
||||
public:
|
||||
~kwsysDeletingCharVector()
|
||||
{
|
||||
for(kwsys_stl::vector<char*>::iterator i = this->begin();
|
||||
i != this->end(); ++i)
|
||||
{
|
||||
delete []*i;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bool SystemTools::PutEnv(const char* value)
|
||||
{
|
||||
static kwsysDeletingCharVector localEnvironment;
|
||||
char* envVar = new char[strlen(value)+1];
|
||||
strcpy(envVar, value);
|
||||
int ret = putenv(envVar);
|
||||
// save the pointer in the static vector so that it can
|
||||
// be deleted on exit
|
||||
localEnvironment.push_back(envVar);
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
|
||||
const char* SystemTools::GetExecutableExtension()
|
||||
{
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
|
|
|
@ -754,6 +754,10 @@ public:
|
|||
static const char* GetEnv(const char* key);
|
||||
static bool GetEnv(const char* key, kwsys_stl::string& result);
|
||||
|
||||
/** Put a string into the environment
|
||||
of the form var=value */
|
||||
static bool PutEnv(const char* value);
|
||||
|
||||
/**
|
||||
* Get current working directory CWD
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue