diff options
author | mathias <mathias> | 2005-05-12 20:03:08 (GMT) |
---|---|---|
committer | mathias <mathias> | 2005-05-12 20:03:08 (GMT) |
commit | 6280b9de0545a8af80ea2f54f5ebe4492a690dbf (patch) | |
tree | d15ce0832a8591869de1d34ab8e4c76beec351f4 | |
parent | c55dce44fafa732a9ff01c3b9ea28df00feff8c7 (diff) | |
download | fluxbox_paul-6280b9de0545a8af80ea2f54f5ebe4492a690dbf.zip fluxbox_paul-6280b9de0545a8af80ea2f54f5ebe4492a690dbf.tar.bz2 |
replaced setenv() completly by putenv(). since putenv() really puts the
*string into the environment we need to track what we putenv.
-rw-r--r-- | src/FbCommands.cc | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 0c62f39..fc3f321 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc | |||
@@ -37,6 +37,7 @@ | |||
37 | 37 | ||
38 | #include <fstream> | 38 | #include <fstream> |
39 | #include <iostream> | 39 | #include <iostream> |
40 | #include <set> | ||
40 | 41 | ||
41 | #ifdef HAVE_CSTDLIB | 42 | #ifdef HAVE_CSTDLIB |
42 | #include <cstdlib> | 43 | #include <cstdlib> |
@@ -145,12 +146,35 @@ ExportCmd::ExportCmd(const std::string& name, const std::string& value) : | |||
145 | } | 146 | } |
146 | 147 | ||
147 | void ExportCmd::execute() { | 148 | void ExportCmd::execute() { |
148 | // TODO: we need to analyze this a bit more | 149 | |
149 | #if defined sgi && ! defined GCC | 150 | // the setenv()-routine is not everywhere available and |
150 | putenv((m_name + "=" + m_value).c_str()); | 151 | // putenv() doesnt manage the strings in the environment |
151 | #else | 152 | // and hence we have to do that on our own to avoid memleaking |
152 | setenv(m_name.c_str(), m_value.c_str(), 1); | 153 | static std::set<char*> stored; |
153 | #endif | 154 | char* newenv = new char[m_name.size() + m_value.size() + 2]; |
155 | if (newenv) { | ||
156 | |||
157 | char* oldenv = getenv(m_name.c_str()); | ||
158 | |||
159 | // oldenv points to the value .. we have to go back a bit | ||
160 | if (oldenv && stored.find(oldenv - (m_name.size() + 1)) != stored.end()) | ||
161 | oldenv -= (m_name.size() + 1); | ||
162 | else | ||
163 | oldenv = NULL; | ||
164 | |||
165 | memset(newenv, 0, m_name.size() + m_value.size() + 2); | ||
166 | strcat(newenv, m_name.c_str()); | ||
167 | strcat(newenv, "="); | ||
168 | strcat(newenv, m_value.c_str()); | ||
169 | |||
170 | if (putenv(newenv) == 0) { | ||
171 | if (oldenv) { | ||
172 | stored.erase(oldenv); | ||
173 | delete[] oldenv; | ||
174 | } | ||
175 | stored.insert(newenv); | ||
176 | } | ||
177 | } | ||
154 | } | 178 | } |
155 | 179 | ||
156 | 180 | ||