fix
This commit is contained in:
34
support/3rd_party/src/utils/path.cpp
vendored
34
support/3rd_party/src/utils/path.cpp
vendored
@@ -36,6 +36,40 @@ static const std::wstring directory_seperator_str_w{
|
||||
} // namespace
|
||||
|
||||
namespace repertory::utils::path {
|
||||
inline auto absolute(std::string_view path) -> std::string {
|
||||
std::string abs_path{path};
|
||||
#ifdef _WIN32
|
||||
if (not abs_path.empty() && ::PathIsRelative(abs_path.c_str())) {
|
||||
std::string temp;
|
||||
temp.resize(MAX_PATH + 1);
|
||||
abs_path = _fullpath(temp.c_str(), abs_path.data(), MAX_PATH);
|
||||
}
|
||||
#else
|
||||
if (not abs_path.empty() && (abs_path.at(0U) != '/')) {
|
||||
auto found{false};
|
||||
std::string tmp{abs_path};
|
||||
do {
|
||||
auto *res = realpath(tmp.c_str(), nullptr);
|
||||
if (res) {
|
||||
abs_path = combine(res, {abs_path.substr(tmp.size())});
|
||||
free(res);
|
||||
found = true;
|
||||
} else if (tmp == ".") {
|
||||
found = true;
|
||||
} else {
|
||||
tmp = dirname(tmp.c_str());
|
||||
}
|
||||
} while (not found);
|
||||
}
|
||||
#endif
|
||||
|
||||
return finalize(abs_path);
|
||||
}
|
||||
|
||||
inline auto absolute(std::wstring_view path) -> std::wstring {
|
||||
return utils::string::from_utf8(absolute(utils::string::to_utf8(path)));
|
||||
}
|
||||
|
||||
auto find_program_in_path(const std::string &name_without_extension)
|
||||
-> std::string {
|
||||
static std::mutex mtx{};
|
||||
|
Reference in New Issue
Block a user