Line data Source code
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 :
17 : #include "okssystem/Environment.hpp"
18 : #include "okssystem/exceptions.hpp"
19 :
20 : using namespace OksSystem;
21 :
22 : /** Sets an environnement variable
23 : * \param key the name of the variable
24 : * \param value the value of the variable
25 : * \exception PosixIssue unable to set environnement variable
26 : */
27 :
28 0 : void OksSystem::Environment::set(const std::string &key, const std::string &value) {
29 0 : const char* c_key = key.c_str();
30 0 : const char* c_value = value.c_str();
31 0 : const int status = ::setenv(c_key,c_value,1);
32 0 : if (status<0) {
33 0 : std::string message = "while setting " + key + " to " + value;
34 0 : throw OksSystemCallIssue( ERS_HERE, errno, "setenv", message.c_str());
35 0 : }
36 0 : } // set
37 :
38 : /** Sets a collection of environnement variables.
39 : * \param values The map of string string pairs containing the name / values pairs
40 : * \exception PosixIssue unable to set environnement variable
41 : */
42 :
43 0 : void OksSystem::Environment::set(const std::map<std::string,std::string> &values) {
44 0 : for(std::map<std::string,std::string>::const_iterator pos = values.begin();pos!=values.end();++pos) {
45 0 : set(pos->first,pos->second);
46 : } // for
47 0 : } // set
48 :
49 : /** Gets an environnement variable
50 : * \param key the name of the variable
51 : * \return the value of the variable, of the string \c NO_VALUE if the variable is unknown.
52 : */
53 :
54 0 : std::string OksSystem::Environment::get(const std::string &key) {
55 0 : const char* c_value = ::getenv(key.c_str());
56 0 : if (c_value==0) return std::string();
57 0 : return std::string(c_value);
58 : } // get
59 :
|