ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Environment.cpp
Revision: 176
Committed: 2004-06-25T20:32:24-07:00 (20 years, 11 months ago) by Douglas Thrift
File size: 831 byte(s)
Log Message:
Almost working, needs error display, and a working api::TcpSocket::Close().

File Contents

# Content
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 }

Properties

Name Value
svn:eol-style native
svn:keywords Id