getenv.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // getenv: Obtain value of environment variable; throw if none such
4 //
5 // ======================================================================
6 
7 #include "cetlib/getenv.h"
8 
9 #include "cetlib_except/exception.h"
10 #include <cstdlib>
11 
12 // ======================================================================
13 
16 {
17  char const* p = std::getenv(name.c_str());
18  if (p == nullptr) {
19  throw cet::exception{"getenv"}
20  << "Can't find an environment variable named \"" << name << '\"';
21  }
22  return p;
23 }
24 
26 cet::getenv(std::string const& name, std::nothrow_t)
27 {
28  char const* p = std::getenv(name.c_str());
29  if (p == nullptr) {
30  p = "";
31  }
32  return p;
33 }
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
std::string getenv(std::string const &name)
Definition: getenv.cc:15
p
Definition: test.py:223
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33