]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Support st_Xtimensec fields in struct stat
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Dec 2023 09:59:20 +0000 (10:59 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Dec 2023 12:24:45 +0000 (13:24 +0100)
This increases file timestamp precision on some BSD-based OSes.

Closes #1369.

cmake/GenerateConfigurationFile.cmake
cmake/config.h.in
src/util/DirEntry.hpp

index 7ff5ae383d7a02ad28b8d184eacfd3ea94ae077e..a732bae08194d2fe0a774660ba991eca48a8ff4e 100644 (file)
@@ -40,18 +40,28 @@ foreach(func IN ITEMS ${functions})
 endforeach()
 
 include(CheckStructHasMember)
+
 check_struct_has_member("struct stat" st_atim sys/stat.h
                         HAVE_STRUCT_STAT_ST_ATIM LANGUAGE CXX)
+check_struct_has_member("struct stat" st_atimensec sys/stat.h
+                        HAVE_STRUCT_STAT_ST_ATIMENSEC LANGUAGE CXX)
 check_struct_has_member("struct stat" st_atimespec sys/stat.h
                         HAVE_STRUCT_STAT_ST_ATIMESPEC LANGUAGE CXX)
+
 check_struct_has_member("struct stat" st_ctim sys/stat.h
                         HAVE_STRUCT_STAT_ST_CTIM LANGUAGE CXX)
+check_struct_has_member("struct stat" st_ctimensec sys/stat.h
+                        HAVE_STRUCT_STAT_ST_CTIMENSEC LANGUAGE CXX)
 check_struct_has_member("struct stat" st_ctimespec sys/stat.h
                         HAVE_STRUCT_STAT_ST_CTIMESPEC LANGUAGE CXX)
+
 check_struct_has_member("struct stat" st_mtim sys/stat.h
                         HAVE_STRUCT_STAT_ST_MTIM LANGUAGE CXX)
+check_struct_has_member("struct stat" st_mtimensec sys/stat.h
+                        HAVE_STRUCT_STAT_ST_MTIMENSEC LANGUAGE CXX)
 check_struct_has_member("struct stat" st_mtimespec sys/stat.h
                         HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE CXX)
+
 check_struct_has_member("struct statfs" f_fstypename sys/mount.h
                         HAVE_STRUCT_STATFS_F_FSTYPENAME LANGUAGE CXX)
 
index 69b50836880c9e0675c0d2a49afdbf60840eb4bd..08e9ad9ace075873292207cec79aa48cdf949d6e 100644 (file)
 // Define if "st_atim" is a member of "struct stat".
 #cmakedefine HAVE_STRUCT_STAT_ST_ATIM
 
+// Define if "st_atimensec" is a member of "struct stat".
+#cmakedefine HAVE_STRUCT_STAT_ST_ATIMENSEC
+
 // Define if "st_atimespec" is a member of "struct stat".
 #cmakedefine HAVE_STRUCT_STAT_ST_ATIMESPEC
 
 // Define if "st_ctim" is a member of "struct stat".
 #cmakedefine HAVE_STRUCT_STAT_ST_CTIM
 
+// Define if "st_ctimensec" is a member of "struct stat".
+#cmakedefine HAVE_STRUCT_STAT_ST_CTIMENSEC
+
 // Define if "st_ctimespec" is a member of "struct stat".
 #cmakedefine HAVE_STRUCT_STAT_ST_CTIMESPEC
 
 // Define if "st_mtim" is a member of "struct stat".
 #cmakedefine HAVE_STRUCT_STAT_ST_MTIM
 
+// Define if "st_mtimensec" is a member of "struct stat".
+#cmakedefine HAVE_STRUCT_STAT_ST_MTIMENSEC
+
 // Define if "st_mtimespec" is a member of "struct stat".
 #cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC
 
index 8d5b5314f412f3d3e3b8e4e9edc79fe03ea8f337..bd16e45c74669004b15f15c377b50533cf1a6539 100644 (file)
@@ -190,6 +190,8 @@ DirEntry::atime() const
   return util::TimePoint(do_stat().st_atim);
 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC)
   return util::TimePoint(do_stat().st_atimespec);
+#elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC)
+  return util::TimePoint(do_stat().st_atime, do_stat().st_atimensec);
 #else
   return util::TimePoint(do_stat().st_atime, 0);
 #endif
@@ -202,6 +204,8 @@ DirEntry::ctime() const
   return util::TimePoint(do_stat().st_ctim);
 #elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
   return util::TimePoint(do_stat().st_ctimespec);
+#elif defined(HAVE_STRUCT_STAT_ST_CTIMENSEC)
+  return util::TimePoint(do_stat().st_ctime, do_stat().st_ctimensec);
 #else
   return util::TimePoint(do_stat().st_ctime, 0);
 #endif
@@ -212,8 +216,10 @@ DirEntry::mtime() const
 {
 #if defined(_WIN32) || defined(HAVE_STRUCT_STAT_ST_MTIM)
   return util::TimePoint(do_stat().st_mtim);
-#elif defined(HAVE_STRUCT_STAT_ST_CTIMESPEC)
+#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
   return util::TimePoint(do_stat().st_mtimespec);
+#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
+  return util::TimePoint(do_stat().st_mtime, do_stat().st_mtimensec);
 #else
   return util::TimePoint(do_stat().st_mtime, 0);
 #endif