gettimeofday.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #if defined(_WIN32) && !defined(__GNUC__) &&!defined(__GCCXML__)
  11. #include "gettimeofday.h"
  12. // From http://www.openasthra.com/c-tidbits/gettimeofday-function-for-windows/
  13. #include "WindowsIncludes.h"
  14. #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
  15. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
  16. #else
  17. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  18. #endif
  19. int gettimeofday(struct timeval *tv, struct timezone *tz)
  20. {
  21. #if defined(WINDOWS_PHONE_8) || defined(WINDOWS_STORE_RT)
  22. // _tzset not supported
  23. (void) tv;
  24. (void) tz;
  25. #else
  26. FILETIME ft;
  27. unsigned __int64 tmpres = 0;
  28. static int tzflag;
  29. if (NULL != tv)
  30. {
  31. GetSystemTimeAsFileTime(&ft);
  32. tmpres |= ft.dwHighDateTime;
  33. tmpres <<= 32;
  34. tmpres |= ft.dwLowDateTime;
  35. /*converting file time to unix epoch*/
  36. tmpres /= 10; /*convert into microseconds*/
  37. tmpres -= DELTA_EPOCH_IN_MICROSECS;
  38. tv->tv_sec = (long)(tmpres / 1000000UL);
  39. tv->tv_usec = (long)(tmpres % 1000000UL);
  40. }
  41. if (NULL != tz)
  42. {
  43. if (!tzflag)
  44. {
  45. _tzset();
  46. tzflag++;
  47. }
  48. tz->tz_minuteswest = _timezone / 60;
  49. tz->tz_dsttime = _daylight;
  50. }
  51. #endif
  52. return 0;
  53. }
  54. #endif
粤ICP备19079148号