12#include <mach-o/dyld.h>
22 namespace fs = std::filesystem;
48 return fs::weakly_canonical(path);
52 return fs::absolute(path);
61 static bool existsFile(
const fs::path &path) {
return fs::exists(path) && fs::is_regular_file(path); }
68 static bool existsDir(
const fs::path &path) {
return fs::exists(path) && fs::is_directory(path); }
83 template <
typename... Paths>
static fs::path
join(
const Paths &...paths)
85 return normalize((fs::path(paths) / ...));
95 char buffer[MAX_PATH];
96 GetModuleFileNameA(NULL, buffer, MAX_PATH);
97 return fs::path(buffer).parent_path();
100 uint32_t size =
sizeof(buffer);
101 if (_NSGetExecutablePath(buffer, &size) == 0)
103 return fs::path(buffer).parent_path();
105 return fs::current_path();
108 if (
const ssize_t count = readlink(
"/proc/self/exe", buffer,
sizeof(buffer)); count != -1)
110 return fs::path(std::string(buffer, count)).parent_path();
112 return fs::current_path();
133 return normalize(fs::current_path() / relativePath);
Class for path resolution utilities.
Path(const Path &)=delete
static fs::path executableDir()
Get the directory of the executable.
static fs::path normalize(const fs::path &path)
Normalize a path (resolve symlinks, relative paths, etc.)
static fs::path join(const Paths &...paths)
Join multiple paths.
static fs::path resolveRelativeToExe(const fs::path &relativePath)
Resolve a relative path to the executable directory.
static bool existsDir(const fs::path &path)
Check if a directory exists.
static fs::path parentDir(const fs::path &path)
Get the parent directory of a path.
static bool existsFile(const fs::path &path)
Check if a file exists.
static fs::path resolveRelativeToCwd(const fs::path &relativePath)
Path & operator=(Path &&)=delete
Path & operator=(const Path &)=delete