plugin_search_path.cc
Go to the documentation of this file.
2 
3 #include "cetlib/os_libpath.h"
5 
6 #include <cstdlib>
7 #include <set>
8 #include <string>
9 
10 namespace {
11  // Prepend specified path to os_libpath(), dropping duplicates.
12  void
13  prepend_path_to_os_libpath(cet::search_path const& sp)
14  {
15  std::string new_os_libpath;
16  std::set<std::string> paths;
17  auto const np_sz = sp.size();
18  for (auto i = 0ull; i != np_sz; ++i) {
19  if (!new_os_libpath.empty()) {
20  new_os_libpath.append(":");
21  }
22  new_os_libpath.append(sp[i]);
23  paths.insert(sp[i]);
24  }
25  cet::search_path oslp{cet::os_libpath(), std::nothrow};
26  auto const oslp_sz = oslp.size();
27  for (auto i = 0ull; i != oslp_sz; ++i) {
28  if (paths.find(oslp[i]) == paths.end()) {
29  if (!new_os_libpath.empty()) {
30  new_os_libpath.append(":");
31  }
32  new_os_libpath.append(oslp[i]);
33  paths.insert(oslp[i]);
34  }
35  }
36  setenv(cet::os_libpath(), new_os_libpath.c_str(), 1);
37  }
38 }
39 
42 {
43  return plugin_search_path(search_path{plugin_libpath(), std::nothrow});
44 }
45 
48 {
49  if (sp.showenv() == plugin_libpath() &&
50  std::getenv(plugin_libpath()) == nullptr) {
51  sp = search_path{os_libpath()};
52  } else {
53  prepend_path_to_os_libpath(sp);
54  }
55  return sp;
56 }
constexpr char const * os_libpath()
Definition: os_libpath.h:12
std::string string
Definition: nybbler.cc:12
std::string const & showenv() const
Definition: search_path.h:50
constexpr char const * plugin_libpath()
std::size_t size() const
Definition: search_path.cc:82
std::string getenv(std::string const &name)
Definition: getenv.cc:15
search_path plugin_search_path()