#include "filesystem.hpp" #include #include #include bool FSLib::exists(const std::string &path) { struct stat path_stat; return stat( path.c_str(), &path_stat ) == 0; } bool FSLib::isDirectory(const std::string &path) { struct stat path_stat; stat( path.c_str(), &path_stat ); return S_ISDIR(path_stat.st_mode); } std::string FSLib::canonical(const std::string &path) { char *canonical_path = static_cast(malloc(PATH_MAX)); if( realpath(path.c_str(), canonical_path) == nullptr ) return ""; std::string canonical_string{canonical_path}; free(canonical_path); return canonical_string; } bool FSLib::rename(const std::string &file_a, const std::string &file_b) { return ::rename( file_a.c_str(), file_b.c_str() ) == 0; }