gettimeofday.c 999 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*====================================================================*
  2. *
  3. * gettimeofday.c - get time of day for Windows;
  4. *
  5. * A gettimeofday implementation for Microsoft Windows;
  6. *
  7. * Public domain code, author "ponnada";
  8. *
  9. *--------------------------------------------------------------------*/
  10. #ifndef GETTIMEOFDAY_SOURCE
  11. #define GETTIMEOFDAY_SOURCE
  12. #include <time.h>
  13. #include <windows.h>
  14. #include <sys/time.h>
  15. int gettimeofday (struct timeval *tv, struct timezone *tz)
  16. {
  17. FILETIME ft;
  18. unsigned __int64 tmpres = 0;
  19. static int tzflag = 0;
  20. if (NULL != tv)
  21. {
  22. GetSystemTimeAsFileTime (&ft);
  23. tmpres |= ft.dwHighDateTime;
  24. tmpres <<= 32;
  25. tmpres |= ft.dwLowDateTime;
  26. tmpres /= 10;
  27. tmpres -= DELTA_EPOCH_IN_MICROSECS;
  28. tv->tv_sec = (long)(tmpres / 1000000UL);
  29. tv->tv_usec = (long)(tmpres % 1000000UL);
  30. }
  31. if (NULL != tz)
  32. {
  33. if (!tzflag)
  34. {
  35. _tzset ();
  36. tzflag++;
  37. }
  38. tz->tz_minuteswest = _timezone / 60;
  39. tz->tz_dsttime = _daylight;
  40. }
  41. return 0;
  42. }
  43. #endif