base_time.c 795 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifdef _WIN32
  2. #include <time.h>
  3. #ifndef METRO
  4. #include <winsock2.h>
  5. #endif
  6. #include <windows.h>
  7. #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
  8. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
  9. #else
  10. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  11. #endif
  12. struct timeval;
  13. int gettimeofday(struct timeval *tv, struct timezone *tz)
  14. {
  15. FILETIME ft;
  16. unsigned __int64 tmpres = 0;
  17. if (tv)
  18. {
  19. GetSystemTimeAsFileTime(&ft);
  20. tmpres |= ft.dwHighDateTime;
  21. tmpres <<= 32;
  22. tmpres |= ft.dwLowDateTime;
  23. tmpres /= 10; /*convert into microseconds*/
  24. /*converting file time to unix epoch*/
  25. tmpres -= DELTA_EPOCH_IN_MICROSECS;
  26. tv->tv_sec = (long)(tmpres / 1000000UL);
  27. tv->tv_usec = (long)(tmpres % 1000000UL);
  28. }
  29. return 0;
  30. }
  31. #else
  32. void fz_gettimeofday_dummy() { }
  33. #endif