| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 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 |
#if 0 |
| 26 |
struct timeval { |
| 27 |
long tv_sec; |
| 28 |
long tv_usec; |
| 29 |
}; |
| 30 |
#endif |
| 31 |
|
| 32 |
struct timezone { |
| 33 |
int tz_minuteswest; |
| 34 |
int tz_dsttime; |
| 35 |
}; |
| 36 |
|
| 37 |
__inline int gettimeofday(struct timeval *tv, struct timezone *tz) |
| 38 |
{ |
| 39 |
FILETIME ft; |
| 40 |
LARGE_INTEGER li; |
| 41 |
__int64 t; |
| 42 |
static int tzflag; |
| 43 |
|
| 44 |
if (tv) |
| 45 |
{ |
| 46 |
GetSystemTimeAsFileTime(&ft); |
| 47 |
li.LowPart = ft.dwLowDateTime; |
| 48 |
li.HighPart = ft.dwHighDateTime; |
| 49 |
t = li.QuadPart; |
| 50 |
t -= EPOCHFILETIME; |
| 51 |
t /= 10; |
| 52 |
tv->tv_sec = (long)(t / 1000000); |
| 53 |
tv->tv_usec = (long)(t % 1000000); |
| 54 |
} |
| 55 |
|
| 56 |
if (tz) |
| 57 |
{ |
| 58 |
if (!tzflag) |
| 59 |
{ |
| 60 |
_tzset(); |
| 61 |
tzflag++; |
| 62 |
} |
| 63 |
tz->tz_minuteswest = _timezone / 60; |
| 64 |
tz->tz_dsttime = _daylight; |
| 65 |
} |
| 66 |
|
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
#else |
| 71 |
|
| 72 |
#include <sys/time.h> |
| 73 |
|
| 74 |
#endif |
| 75 |
|
| 76 |
#endif |