Explorar o código

Merge topic 'osx-file-times-ns-precision'

8d27b407 cmFileTimeComparison: Port to OS X nanosecond times (#15769)
Brad King %!s(int64=10) %!d(string=hai) anos
pai
achega
1a0da7d320
Modificáronse 2 ficheiros con 36 adicións e 0 borrados
  1. 1 0
      Source/CMakeLists.txt
  2. 35 0
      Source/cmFileTimeComparison.cxx

+ 1 - 0
Source/CMakeLists.txt

@@ -550,6 +550,7 @@ endforeach()
 
 
 foreach(check
 foreach(check
     STAT_HAS_ST_MTIM
     STAT_HAS_ST_MTIM
+    STAT_HAS_ST_MTIMESPEC
     )
     )
   if(KWSYS_CXX_${check}_COMPILED) # abuse KWSys check cache entry
   if(KWSYS_CXX_${check}_COMPILED) # abuse KWSys check cache entry
     set(CMake_${check} 1)
     set(CMake_${check} 1)

+ 35 - 0
Source/cmFileTimeComparison.cxx

@@ -166,6 +166,24 @@ int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1,
     {
     {
     return 1;
     return 1;
     }
     }
+# elif CMake_STAT_HAS_ST_MTIMESPEC
+  // Compare using nanosecond resolution.
+  if(s1->st_mtimespec.tv_sec < s2->st_mtimespec.tv_sec)
+    {
+    return -1;
+    }
+  else if(s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec)
+    {
+    return 1;
+    }
+  else if(s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec)
+    {
+    return -1;
+    }
+  else if(s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec)
+    {
+    return 1;
+    }
 # else
 # else
   // Compare using 1 second resolution.
   // Compare using 1 second resolution.
   if(s1->st_mtime < s2->st_mtime)
   if(s1->st_mtime < s2->st_mtime)
@@ -207,6 +225,23 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
     {
     {
     return false;
     return false;
     }
     }
+# elif CMake_STAT_HAS_ST_MTIMESPEC
+  // Times are integers in units of 1ns.
+  long long bil = 1000000000;
+  long long t1 = s1->st_mtimespec.tv_sec * bil + s1->st_mtimespec.tv_nsec;
+  long long t2 = s2->st_mtimespec.tv_sec * bil + s2->st_mtimespec.tv_nsec;
+  if(t1 < t2)
+    {
+    return (t2 - t1) >= bil;
+    }
+  else if(t2 < t1)
+    {
+    return (t1 - t2) >= bil;
+    }
+  else
+    {
+    return false;
+    }
 # else
 # else
   // Times are integers in units of 1s.
   // Times are integers in units of 1s.
   if(s1->st_mtime < s2->st_mtime)
   if(s1->st_mtime < s2->st_mtime)