move path comparison to pathut

This commit is contained in:
Jean-Francois Dockes
2020-09-28 14:03:05 +02:00
parent eb58602b5d
commit 90f39ffacc
3 changed files with 25 additions and 20 deletions
+20
View File
@@ -969,6 +969,26 @@ long long path_filesize(const string& path)
return (long long)st.st_size;
}
bool path_samefile(const std::string& p1, const std::string& p2)
{
#ifdef _WIN32
std::string cp1, cp2;
cp1 = path_canon(p1);
cp2 = path_canon(p2);
return !cp1.compare(cp2);
#else
struct stat st1, st2;
if (stat(p1.c_str(), &st1))
return false;
if (stat(p2.c_str(), &st2))
return false;
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
return true;
}
return false;
#endif
}
int path_fileprops(const std::string path, struct PathStat *stp, bool follow)
{
if (nullptr == stp) {
+2
View File
@@ -75,6 +75,8 @@ extern bool path_isfile(const std::string& path, bool follow = false);
/// Retrieve file size
extern long long path_filesize(const std::string& path);
bool path_samefile(const std::string& p1, const std::string& p2);
/// Retrieve essential file attributes. This is used rather than a
/// bare stat() to ensure consistent use of the time fields (on
/// windows, we set ctime=mtime as ctime is actually the creation