gettimeofday.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef __GET_TIME_OF_DAY_H
  11. #define __GET_TIME_OF_DAY_H
  12. #if defined(_WIN32) && !defined(__GNUC__) &&!defined(__GCCXML__)
  13. #include < time.h >
  14. struct timezone
  15. {
  16. int tz_minuteswest; /* minutes W of Greenwich */
  17. int tz_dsttime; /* type of dst correction */
  18. };
  19. #if defined(WINDOWS_STORE_RT)
  20. struct timeval {
  21. long tv_sec;
  22. long tv_usec;
  23. };
  24. #endif
  25. int gettimeofday(struct timeval *tv, struct timezone *tz);
  26. #else
  27. #include <sys/time.h>
  28. #include <unistd.h>
  29. // Uncomment this if you need to
  30. /*
  31. // http://www.halcode.com/archives/2008/08/26/retrieving-system-time-gettimeofday/
  32. struct timezone
  33. {
  34. int tz_minuteswest;
  35. int tz_dsttime;
  36. };
  37. #ifdef __cplusplus
  38. void GetSystemTimeAsFileTime(FILETIME*);
  39. inline int gettimeofday(struct timeval* p, void* tz )
  40. {
  41. union {
  42. long long ns100; // time since 1 Jan 1601 in 100ns units
  43. FILETIME ft;
  44. } now;
  45. GetSystemTimeAsFileTime( &(now.ft) );
  46. p->tv_usec=(long)((now.ns100 / 10LL) % 1000000LL );
  47. p->tv_sec= (long)((now.ns100-(116444736000000000LL))/10000000LL);
  48. return 0;
  49. }
  50. #else
  51. int gettimeofday(struct timeval* p, void* tz );
  52. #endif
  53. */
  54. #endif
  55. #endif
粤ICP备19079148号