Leaked source code of windows server 2003
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.

40 lines
1.2 KiB

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