aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/App.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/App.cc')
-rw-r--r--src/FbTk/App.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/FbTk/App.cc b/src/FbTk/App.cc
index 39cd36e..8157839 100644
--- a/src/FbTk/App.cc
+++ b/src/FbTk/App.cc
@@ -26,6 +26,21 @@
26 26
27#include "EventManager.hh" 27#include "EventManager.hh"
28 28
29#ifdef HAVE_CSTRING
30 #include <cstring>
31#else
32 #include <string.h>
33#endif
34#ifdef HAVE_CSTDLIB
35 #include <cstdlib>
36#else
37 #include <stdlib.h>
38#endif
39
40
41#include <set>
42
43
29namespace FbTk { 44namespace FbTk {
30 45
31App *App::s_app = 0; 46App *App::s_app = 0;
@@ -79,4 +94,44 @@ void App::end() {
79 m_done = true; //end loop in App::eventLoop 94 m_done = true; //end loop in App::eventLoop
80} 95}
81 96
97bool App::setenv(const char* key, const char* value) {
98
99 if (!key || !*key)
100 return false;
101
102 static std::set<char*> stored;
103
104 const size_t key_size = strlen(key);
105 const size_t value_size = value ? strlen(value) : 0;
106
107 char* newenv = new char[key_size + value_size + 2];
108 if (newenv) {
109
110 char* oldenv = getenv(key);
111
112 // oldenv points to the value .. we have to go back a bit
113 if (oldenv && stored.find(oldenv - (key_size + 1)) != stored.end())
114 oldenv -= (key_size + 1);
115 else
116 oldenv = NULL;
117
118 memset(newenv, 0, key_size + value_size + 2);
119 strcat(newenv, key);
120 strcat(newenv, "=");
121 if (value_size > 0)
122 strcat(newenv, value);
123
124 if (putenv(newenv) == 0) {
125 if (oldenv) {
126 stored.erase(oldenv);
127 delete[] oldenv;
128 }
129 stored.insert(newenv);
130 }
131 return true;
132 }
133
134 return false;
135}
136
82} // end namespace FbTk 137} // end namespace FbTk