Annotation of imach/src/timeval.h, revision 1.1
1.1 ! brouard 1: /*
! 2: * timeval.h 1.0 01/12/19
! 3: *
! 4: * Defines gettimeofday, timeval, etc. for Win32
! 5: *
! 6: * By Wu Yongwei
! 7: *
! 8: */
! 9:
! 10: #ifndef _TIMEVAL_H
! 11: #define _TIMEVAL_H
! 12:
! 13: #ifdef _WIN32
! 14:
! 15: #define WIN32_LEAN_AND_MEAN
! 16: #include <windows.h>
! 17: #include <time.h>
! 18:
! 19: #ifndef __GNUC__
! 20: #define EPOCHFILETIME (116444736000000000i64)
! 21: #else
! 22: #define EPOCHFILETIME (116444736000000000LL)
! 23: #endif
! 24:
! 25: struct timeval {
! 26: long tv_sec; /* seconds */
! 27: long tv_usec; /* microseconds */
! 28: };
! 29:
! 30: struct timezone {
! 31: int tz_minuteswest; /* minutes W of Greenwich */
! 32: int tz_dsttime; /* type of dst correction */
! 33: };
! 34:
! 35: __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
! 36: {
! 37: FILETIME ft;
! 38: LARGE_INTEGER li;
! 39: __int64 t;
! 40: static int tzflag;
! 41:
! 42: if (tv)
! 43: {
! 44: GetSystemTimeAsFileTime(&ft);
! 45: li.LowPart = ft.dwLowDateTime;
! 46: li.HighPart = ft.dwHighDateTime;
! 47: t = li.QuadPart; /* In 100-nanosecond intervals */
! 48: t -= EPOCHFILETIME; /* Offset to the Epoch time */
! 49: t /= 10; /* In microseconds */
! 50: tv->tv_sec = (long)(t / 1000000);
! 51: tv->tv_usec = (long)(t % 1000000);
! 52: }
! 53:
! 54: if (tz)
! 55: {
! 56: if (!tzflag)
! 57: {
! 58: _tzset();
! 59: tzflag++;
! 60: }
! 61: tz->tz_minuteswest = _timezone / 60;
! 62: tz->tz_dsttime = _daylight;
! 63: }
! 64:
! 65: return 0;
! 66: }
! 67:
! 68: #else /* _WIN32 */
! 69:
! 70: #include <sys/time.h>
! 71:
! 72: #endif /* _WIN32 */
! 73:
! 74: #endif /* _TIMEVAL_H */
! 75:
! 76:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>