21#include <RConfigure.h>
38#include <sys/syslimits.h>
43#include <libprocstat.h>
50 char fixedLength[1024];
51 char *currWorkDir = fixedLength;
53 char *result = currWorkDir;
58 if (fixedLength != currWorkDir) {
61 currWorkDir =
new char[len];
64 result = ::_getcwd(currWorkDir, len);
66 result = getcwd(currWorkDir, len);
68 }
while (!result && errno == ERANGE);
70 std::string output = currWorkDir;
74 std::replace(output.begin(), output.end(),
'\\',
'/');
77 if (fixedLength != currWorkDir) {
83std::string
MakePathRelative(
const std::string &path,
const std::string &base,
bool isBuildingROOT )
85 std::string result(path);
87 const char *currWorkDir = base.c_str();
88 size_t lenCurrWorkDir = strlen(currWorkDir);
89 if (result.substr(0, lenCurrWorkDir) == currWorkDir) {
93 result.erase(0, lenCurrWorkDir);
99 int posInc = result.find(
"/inc/");
101 result = result.substr(posInc + 5);
109 std::replace(Path.begin(), Path.end(),
'\\',
'/');
113 static std::string fallback;
114 if (!fallback.empty())
117#if defined(WIN32) || defined(__FreeBSD__)
118 auto parent_path = [](std::string path) {
119 return path.substr(0, path.find_last_of(
"/\\"));
124 static char lpFilename[_MAX_PATH];
125 if (::GetModuleFileNameA(
128 sizeof(lpFilename))) {
129 fallback = parent_path(parent_path(lpFilename));
131#elif defined __FreeBSD__
132 procstat* ps = procstat_open_sysctl();
133 kinfo_proc* kp = kinfo_getproc(getpid());
135 char lpFilename[PATH_MAX] =
"";
137 procstat_getpathname(ps, kp, lpFilename,
sizeof(lpFilename));
138 fallback = parent_path(parent_path({lpFilename}));
147 fallback =
"/usr/local/root";
153static bool IgnorePrefix() {
154 static bool ignorePrefix = std::getenv(
"ROOTIGNOREPREFIX");
161 if (!IgnorePrefix()) {
162 const static std::string rootsys = ROOTPREFIX;
166 static std::string rootsys;
167 if (rootsys.empty()) {
168 if (
const char* envValue = std::getenv(
"ROOTSYS")) {
184 if (!IgnorePrefix()) {
185 const static std::string rootetcdir = ROOTETCDIR;
190 const static std::string rootetcdir =
196 std::transform(s.begin(), s.end(), s.begin(),
197 [](
unsigned char c){ return std::tolower(c); });
The file contains utilities which are foundational and could be used across the core component of ROO...
static int lowercase(const char *s)
const std::string & GetPathSeparator()
std::string GetCurrentDir()
static std::string str_tolower(std::string s)
void ConvertToUnixPath(std::string &Path)
Transforms a file path by replacing its backslashes with slashes.
bool CanConvertEnvValueToBool(const std::string &value)
const std::string & GetRootSys()
std::string MakePathRelative(const std::string &path, const std::string &base, bool isBuildingROOT=false)
bool ConvertEnvValueToBool(const std::string &value)
const std::string & GetFallbackRootSys()
const std::string & GetEtcDir()