1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
mold/filepath.cc

28 lines
709 B
C++
Raw Normal View History

2021-03-08 09:25:23 +03:00
#include "mold.h"
#include <filesystem>
2021-11-30 09:23:00 +03:00
#include <sys/stat.h>
namespace mold {
2021-11-27 13:57:38 +03:00
std::string get_realpath(std::string_view path) {
std::error_code ec;
std::string ret = std::filesystem::canonical(path, ec);
return ec ? std::string(path) : ret;
2021-04-09 10:05:52 +03:00
}
2021-04-18 07:30:55 +03:00
// Removes redundant '/..' or '/.' from a given path.
// The transformation is done purely by lexical processing.
// This function does not access file system.
2021-03-16 18:26:28 +03:00
std::string path_clean(std::string_view path) {
return filepath(path).lexically_normal();
}
std::filesystem::path to_abs_path(std::filesystem::path path) {
if (path.is_absolute())
return path;
return (std::filesystem::current_path() / path).lexically_normal();
2021-03-16 18:26:28 +03:00
}
} // namespace mold