1 |
// Smersh |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include "Environment.hpp" |
8 |
|
9 |
string Environment::get(const string& name) const |
10 |
{ |
11 |
map<string, string>::const_iterator itor(env.find(name)); |
12 |
|
13 |
if (itor != env.end()) return itor->second; |
14 |
|
15 |
char* value(getenv(name.c_str())); |
16 |
|
17 |
return value != NULL ? value : ""; |
18 |
} |
19 |
|
20 |
int Environment::set(const string& name, const string& value, bool overwrite) |
21 |
{ |
22 |
pair<map<string, string>::iterator, bool> itor(env.insert(pair<string, |
23 |
string>(name, value))); |
24 |
|
25 |
if (!itor.second && overwrite) itor.first->second = value; |
26 |
|
27 |
return 0; |
28 |
} |
29 |
|
30 |
int Environment::put(const string& env) |
31 |
{ |
32 |
istringstream input(env); |
33 |
string name, value; |
34 |
|
35 |
getline(input, name, '='); |
36 |
getline(input, value); |
37 |
|
38 |
return set(name, value); |
39 |
} |
40 |
|
41 |
void Environment::unset(const string& name) |
42 |
{ |
43 |
if (env.erase(name) == 0) unsetenv(name.c_str()); |
44 |
} |