21 #include <RConfigure.h>
35 namespace FoundationUtils {
36 std::string GetCurrentDir()
38 char fixedLength[1024];
39 char *currWorkDir = fixedLength;
41 char *result = currWorkDir;
46 if (fixedLength != currWorkDir) {
49 currWorkDir =
new char[len];
52 result = ::_getcwd(currWorkDir, len);
54 result = getcwd(currWorkDir, len);
56 }
while (result == 0 && errno == ERANGE);
58 std::string output = currWorkDir;
62 std::replace(output.begin(), output.end(),
'\\',
'/');
65 if (fixedLength != currWorkDir) {
71 std::string MakePathRelative(
const std::string &path,
const std::string &base,
bool isBuildingROOT )
73 std::string result(path);
75 const char *currWorkDir = base.c_str();
76 size_t lenCurrWorkDir = strlen(currWorkDir);
77 if (result.substr(0, lenCurrWorkDir) == currWorkDir) {
81 result.erase(0, lenCurrWorkDir);
87 int posInc = result.find(
"/inc/");
89 result = result.substr(posInc + 5, -1);
96 void ConvertToUnixPath(std::string& Path) {
97 std::replace(Path.begin(), Path.end(),
'\\',
'/');
100 const std::string& GetFallbackRootSys() {
101 static std::string fallback;
102 if (!fallback.empty())
105 static char lpFilename[_MAX_PATH];
106 if (::GetModuleFileNameA(
109 sizeof(lpFilename))) {
110 auto parent_path = [](std::string path) {
111 return path.substr(0, path.find_last_of(
"/\\"));
113 fallback = parent_path(parent_path(lpFilename));
119 fallback =
"/usr/local/root";
125 static bool IgnorePrefix() {
126 static bool ignorePrefix = ::getenv(
"ROOTIGNOREPREFIX");
131 const std::string& GetRootSys() {
133 if (!IgnorePrefix()) {
134 const static std::string rootsys = ROOTPREFIX;
138 static std::string rootsys;
139 if (rootsys.empty()) {
140 if (
const char* envValue = ::getenv(
"ROOTSYS")) {
143 ConvertToUnixPath(rootsys);
148 rootsys = GetFallbackRootSys();
153 const std::string& GetIncludeDir() {
155 if (!IgnorePrefix()) {
156 const static std::string rootincdir = ROOTINCDIR;
160 static std::string rootincdir;
161 if (rootincdir.empty()) {
162 const std::string& sep = GetPathSeparator();
163 rootincdir = GetRootSys() + sep +
"include" + sep;
168 const std::string& GetEtcDir() {
170 if (!IgnorePrefix()) {
171 const static std::string rootetcdir = ROOTETCDIR;
176 const static std::string rootetcdir =
177 GetRootSys() + GetPathSeparator() +
"etc" + GetPathSeparator();;