sys_time.h 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef SYS_TIME_H_
  2. #define SYS_TIME_H_
  3. #include <time.h>
  4. #include <winsock2.h>
  5. struct timezone
  6. {
  7. int tz_minuteswest; /* minutes W of Greenwich */
  8. int tz_dsttime; /* type of dst correction */
  9. };
  10. static __inline int gettimeofday(struct timeval *tp, struct timezone * tzp)
  11. {
  12. FILETIME file_time;
  13. SYSTEMTIME system_time;
  14. ULARGE_INTEGER ularge;
  15. static int tzflag;
  16. GetSystemTime(&system_time);
  17. SystemTimeToFileTime(&system_time, &file_time);
  18. ularge.LowPart = file_time.dwLowDateTime;
  19. ularge.HighPart = file_time.dwHighDateTime;
  20. tp->tv_sec = (long)((ularge.QuadPart - 116444736000000000Ui64) / 10000000L);
  21. tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
  22. if (NULL != tzp)
  23. {
  24. if (!tzflag)
  25. {
  26. _tzset();
  27. tzflag++;
  28. }
  29. tzp->tz_minuteswest = _timezone / 60;
  30. tzp->tz_dsttime = _daylight;
  31. }
  32. return 0;
  33. }
  34. #endif