DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Environment.cpp
Go to the documentation of this file.
1/*
2 * Environment.cxx
3 * ers
4 *
5 * Created by Matthias Wiesmann on 11.01.05.
6 * Copyright 2005 CERN. All rights reserved.
7 *
8 */
9
10#include <stdlib.h>
11
14
15using namespace OksSystem;
16
23void OksSystem::Environment::set(const std::string &key, const std::string &value) {
24 const char* c_key = key.c_str();
25 const char* c_value = value.c_str();
26 const int status = ::setenv(c_key,c_value,1);
27 if (status<0) {
28 std::string message = "while setting " + key + " to " + value;
29 throw OksSystemCallIssue( ERS_HERE, errno, "setenv", message.c_str());
30 }
31} // set
32
38void OksSystem::Environment::set(const std::map<std::string,std::string> &values) {
39 for(std::map<std::string,std::string>::const_iterator pos = values.begin();pos!=values.end();++pos) {
40 set(pos->first,pos->second);
41 } // for
42} // set
43
49std::string OksSystem::Environment::get(const std::string &key) {
50 const char* c_value = ::getenv(key.c_str());
51 if (c_value==0) return std::string();
52 return std::string(c_value);
53} // get
54
#define ERS_HERE
static std::string get(const std::string &key)
get a environnement variable
static void set(const std::string &key, const std::string &value)
sets an environnement variable