Mercurial > defical
comparison defical-c/src/msvc/gettimeofday.c @ 0:ebed2bd0d300
Initial import from svn. History be damned.
author | Edho P. Arief <me@myconan.net> |
---|---|
date | Fri, 02 Apr 2010 23:11:57 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ebed2bd0d300 |
---|---|
1 #include <time.h> | |
2 #include <windows.h> | |
3 | |
4 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) | |
5 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 | |
6 #else | |
7 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL | |
8 #endif | |
9 | |
10 struct timezone | |
11 { | |
12 int tz_minuteswest; /* minutes W of Greenwich */ | |
13 int tz_dsttime; /* type of dst correction */ | |
14 }; | |
15 | |
16 int gettimeofday(struct timeval *tv, struct timezone *tz) | |
17 { | |
18 FILETIME ft; | |
19 unsigned __int64 tmpres = 0; | |
20 static int tzflag = 0; | |
21 | |
22 if (NULL != tv) | |
23 { | |
24 GetSystemTimeAsFileTime(&ft); | |
25 | |
26 tmpres |= ft.dwHighDateTime; | |
27 tmpres <<= 32; | |
28 tmpres |= ft.dwLowDateTime; | |
29 | |
30 tmpres /= 10; /*convert into microseconds*/ | |
31 /*converting file time to unix epoch*/ | |
32 tmpres -= DELTA_EPOCH_IN_MICROSECS; | |
33 tv->tv_sec = (long)(tmpres / 1000000UL); | |
34 tv->tv_usec = (long)(tmpres % 1000000UL); | |
35 } | |
36 | |
37 if (NULL != tz) | |
38 { | |
39 if (!tzflag) | |
40 { | |
41 _tzset(); | |
42 tzflag++; | |
43 } | |
44 tz->tz_minuteswest = _get_timezone(tz) / 60; | |
45 tz->tz_dsttime = _daylight; | |
46 } | |
47 | |
48 return 0; | |
49 } | |
50 | |
51 |