summaryrefslogtreecommitdiff
path: root/src/FbCommands.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbCommands.cc')
-rw-r--r--src/FbCommands.cc36
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
147void ExportCmd::execute() { 148void 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