From fdff8eb300872af8546b738c0ffc4ac704d5feac Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Fri, 5 Jun 2009 12:01:30 -0400 Subject: ENH: move PutEnv to SystemTools --- Source/cmSystemTools.cxx | 26 -------------------------- Source/cmSystemTools.h | 4 ---- Source/kwsys/SystemTools.cxx | 27 +++++++++++++++++++++++++++ Source/kwsys/SystemTools.hxx.in | 4 ++++ 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 91c6df7..d907288 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -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 -{ -public: - ~cmDeletingCharVector() - { - for(std::vector::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) diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 00b4873..0974759 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -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); 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 +{ +public: + ~kwsysDeletingCharVector() + { + for(kwsys_stl::vector::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 */ -- cgit v0.12