DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Environment.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS system source for the DUNE DAQ project.
3// Fork baseline commit: system-00-00-20 (2020-09-25).
4// Renamed since fork: yes (from src/Environment.cxx to src/Environment.cpp).
5
6/*
7 * Environment.cxx
8 * ers
9 *
10 * Created by Matthias Wiesmann on 11.01.05.
11 * Copyright 2005 CERN. All rights reserved.
12 *
13 */
14
15#include <stdlib.h>
16
19
20using namespace OksSystem;
21
27
28void
29OksSystem::Environment::set(const std::string& key, const std::string& value)
30{
31 const char* c_key = key.c_str();
32 const char* c_value = value.c_str();
33 const int status = ::setenv(c_key, c_value, 1);
34 if (status < 0) {
35 std::string message = "while setting " + key + " to " + value;
36 throw OksSystemCallIssue(ERS_HERE, errno, "setenv", message.c_str());
37 }
38} // set
39
44
45void
46OksSystem::Environment::set(const std::map<std::string, std::string>& values)
47{
48 for (std::map<std::string, std::string>::const_iterator pos = values.begin(); pos != values.end(); ++pos) {
49 set(pos->first, pos->second);
50 } // for
51} // set
52
57
58std::string
59OksSystem::Environment::get(const std::string& key)
60{
61 const char* c_value = ::getenv(key.c_str());
62 if (c_value == 0)
63 return std::string();
64 return std::string(c_value);
65} // get
#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