Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

  1. #include "h/ref.hxx"
  2. #include "time.hxx"
  3. #include "h/ole.hxx"
  4. #include <limits.h>
  5. #include <assert.h>
  6. // Number of seconds difference betwen FILETIME (since 1601 00:00:00)
  7. // and time_t (since 1970 00:00:00)
  8. //
  9. // This should be a constant difference between the 2 time formats
  10. //
  11. #ifdef __GNUC__ // cater to differences of compiler syntax
  12. const LONGLONG ci64DiffFTtoTT=11644473600LL;
  13. #else // __GNUC__
  14. const LONGLONG ci64DiffFTtoTT=11644473600;
  15. #endif // __GNUC__
  16. STDAPI_(void) FileTimeToTimeT(const FILETIME *pft, time_t *ptt)
  17. {
  18. ULONGLONG llFT = pft->dwHighDateTime;
  19. llFT = (llFT << 32) | (pft->dwLowDateTime);
  20. // convert to seconds
  21. // (note that all fractions of seconds will be lost)
  22. llFT = llFT/10000000;
  23. llFT -= ci64DiffFTtoTT; // convert to time_t
  24. assert(llFT <= ULONG_MAX);
  25. *ptt = (time_t) llFT;
  26. }
  27. STDAPI_(void) TimeTToFileTime(const time_t *ptt, FILETIME *pft)
  28. {
  29. ULONGLONG llFT = *ptt;
  30. llFT += ci64DiffFTtoTT; // convert to file time
  31. // convert to nano-seconds
  32. for (int i=0; i<7; i++) // mulitply by 10 7 times
  33. {
  34. llFT = llFT << 1; // llFT = 2x
  35. llFT += (llFT << 2); // llFT = 4*2x + 2x = 10x
  36. }
  37. pft->dwLowDateTime = (DWORD) (llFT & 0xffffffff);
  38. pft->dwHighDateTime = (DWORD) (llFT >> 32);
  39. }
  40. #ifdef _MSC_VER
  41. #pragma warning(disable:4514)
  42. // disable warning about unreferenced inline functions
  43. #endif