21 #include <RConfigure.h>
36 namespace FoundationUtils {
39 char fixedLength[1024];
40 char *currWorkDir = fixedLength;
42 char *result = currWorkDir;
47 if (fixedLength != currWorkDir) {
50 currWorkDir =
new char[len];
53 result = ::_getcwd(currWorkDir, len);
55 result = getcwd(currWorkDir, len);
57 }
while (result == 0 && errno == ERANGE);
59 std::string
output = currWorkDir;
66 if (fixedLength != currWorkDir) {
72 std::string
MakePathRelative(
const std::string &path,
const std::string &base,
bool isBuildingROOT )
74 std::string result(path);
76 const char *currWorkDir = base.c_str();
77 size_t lenCurrWorkDir = strlen(currWorkDir);
78 if (result.substr(0, lenCurrWorkDir) == currWorkDir) {
82 result.erase(0, lenCurrWorkDir);
88 int posInc = result.find(
"/inc/");
90 result = result.substr(posInc + 5, -1);
98 std::replace(Path.begin(), Path.end(),
'\\',
'/');
102 static std::string fallback;
103 if (!fallback.empty())
106 static char lpFilename[_MAX_PATH];
107 if (::GetModuleFileNameA(
110 sizeof(lpFilename))) {
111 auto parent_path = [](std::string path) {
112 return path.substr(0, path.find_last_of(
"/\\"));
114 fallback = parent_path(parent_path(lpFilename));
120 fallback =
"/usr/local/root";
126 static bool IgnorePrefix() {
127 static bool ignorePrefix = ::getenv(
"ROOTIGNOREPREFIX");
134 if (!IgnorePrefix()) {
135 const static std::string rootsys = ROOTPREFIX;
139 static std::string rootsys;
140 if (rootsys.empty()) {
141 if (
const char* envValue = ::getenv(
"ROOTSYS")) {
156 if (!IgnorePrefix()) {
157 const static std::string rootincdir = ROOTINCDIR;
161 static std::string rootincdir;
162 if (rootincdir.empty()) {
171 if (!IgnorePrefix()) {
172 const static std::string rootetcdir = ROOTETCDIR;
177 const static std::string rootetcdir =
183 std::transform(
s.begin(),
s.end(),
s.begin(),
184 [](
unsigned char c){ return std::tolower(c); });