gettimeofday.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "precompile.h"
  2. #include "gettimeofday.h"
  3. #include <errno.h>
  4. #define EPOCHFILETIME (116444736000000000i64)
  5. TOOLKIT_API int gettimeofday(struct timeval *tp, struct timezone *tzp)
  6. {
  7. SYSTEMTIME st;
  8. FILETIME ft;
  9. LARGE_INTEGER li;
  10. TIME_ZONE_INFORMATION tzi;
  11. __int64 t;
  12. static int tzflag;
  13. if (NULL != tp)
  14. {
  15. GetSystemTime(&st);
  16. SystemTimeToFileTime(&st, &ft);
  17. li.LowPart = ft.dwLowDateTime;
  18. li.HighPart = ft.dwHighDateTime;
  19. t = li.QuadPart; /* In 100-nanosecond intervals */
  20. t -= EPOCHFILETIME; /* Offset to the Epoch time */
  21. t /= 10; /* In microseconds */
  22. tp->tv_sec = (long)(t / 1000000);
  23. tp->tv_usec = (long)(t % 1000000);
  24. }
  25. if (NULL != tzp)
  26. {
  27. GetTimeZoneInformation(&tzi);
  28. tzp->tz_minuteswest = tzi.Bias;
  29. if (tzi.StandardDate.wMonth != 0)
  30. {
  31. tzp->tz_minuteswest += tzi.StandardBias * 60;
  32. }
  33. if (tzi.DaylightDate.wMonth != 0)
  34. {
  35. tzp->tz_dsttime = 1;
  36. }
  37. else
  38. {
  39. tzp->tz_dsttime = 0;
  40. }
  41. }
  42. return 0;
  43. }