-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilepath.cc
More file actions
27 lines (21 loc) · 746 Bytes
/
filepath.cc
File metadata and controls
27 lines (21 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "mold.h"
#include <filesystem>
#include <sys/stat.h>
namespace mold {
std::string get_realpath(std::string_view path) {
std::error_code ec;
std::string ret = std::filesystem::canonical(path, ec).string();
return ec ? std::string(path) : ret;
}
// Removes redundant '/..' or '/.' from a given path.
// The transformation is done purely by lexical processing.
// This function does not access file system.
std::string path_clean(std::string_view path) {
return filepath(path).lexically_normal().string();
}
std::filesystem::path to_abs_path(std::filesystem::path path) {
if (path.is_absolute())
return path.lexically_normal();
return (std::filesystem::current_path() / path).lexically_normal();
}
} // namespace mold