diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2009-06-05 16:01:30 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2009-06-05 16:01:30 (GMT) |
commit | fdff8eb300872af8546b738c0ffc4ac704d5feac (patch) | |
tree | ed5c6e5e82c0ecc75d19ef2b2ba86657537eaa51 /Source/kwsys | |
parent | d5f80203918c7428c90735c43bce7ed2865bda83 (diff) | |
download | CMake-fdff8eb300872af8546b738c0ffc4ac704d5feac.zip CMake-fdff8eb300872af8546b738c0ffc4ac704d5feac.tar.gz CMake-fdff8eb300872af8546b738c0ffc4ac704d5feac.tar.bz2 |
ENH: move PutEnv to SystemTools
Diffstat (limited to 'Source/kwsys')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 27 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.hxx.in | 4 |
2 files changed, 31 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 2d90de2..45c4969 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -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__) diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 31a876d..8cba810 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -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 */ |