Windows: Rewrite LargeSearchTime conversions
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 27 Nov 2013 19:41:18 +0000 (14:41 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Mon, 30 Dec 2013 07:51:09 +0000 (23:51 -0800)
Use LARGE_INTEGER to avoid the need for shifting and DWORD casts.
Take into account the size of time_t.

Change-Id: I056d920894b661ebb2060a5010efd9a0cd5a4a5d
Reviewed-on: http://gerrit.openafs.org/10673
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsd/cm_utils.c

index 6cf4209..6c7718e 100644 (file)
@@ -1053,26 +1053,29 @@ void cm_UpdateServerPriority()
 void cm_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, time_t unixTime)
 {
     // Note that LONGLONG is a 64-bit value
-    LONGLONG ll;
-
-    ll = Int32x32To64(unixTime, 10000000) + 116444736000000000;
-    largeTimep->dwLowDateTime = (DWORD)(ll & 0xFFFFFFFF);
-    largeTimep->dwHighDateTime = (DWORD)(ll >> 32);
+    LARGE_INTEGER ll;
+
+#ifdef _USE_32BIT_TIME_T
+    ll.QuadPart = UInt32x32To64(unixTime, 10000000) + 116444736000000000;
+#else
+    ll.QuadPart = unixTime * 10000000 + 116444736000000000;
+#endif
+    largeTimep->dwLowDateTime = ll.LowPart;
+    largeTimep->dwHighDateTime = ll.HighPart;
 }
 
 void cm_UnixTimeFromLargeSearchTime(time_t *unixTimep, FILETIME *largeTimep)
 {
     // Note that LONGLONG is a 64-bit value
-    LONGLONG ll;
+    LARGE_INTEGER ll;
 
-    ll = largeTimep->dwHighDateTime;
-    ll <<= 32;
-    ll += largeTimep->dwLowDateTime;
+    ll.HighPart = largeTimep->dwHighDateTime;
+    ll.LowPart  = largeTimep->dwLowDateTime;
 
-    ll -= 116444736000000000;
-    ll /= 10000000;
+    ll.QuadPart -= 116444736000000000;
+    ll.QuadPart /= 10000000;
 
-    *unixTimep = (DWORD)ll;
+    *unixTimep = (time_t)ll.QuadPart;
 }
 
 void cm_SearchTimeFromUnixTime(afs_uint32 *searchTimep, time_t unixTime)