summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-02 01:19:07 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-02 01:19:07 +0000
commitd1f4a0fafa6286ef0e244a4e5f0cc75fefab735c (patch)
tree34005a9cddba1c4a84ff864ef21f14556d00c480 /win32/win32.c
parentea75c908dcd25d91243dba50dd1a38ea08849500 (diff)
* win32/win32.c (gettimeofday): calc tv_sec and tv_usec from system
time by myself. [ruby-dev:36084] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@19050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 0a0c3a299c..13ddbd374b 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2978,12 +2978,24 @@ waitpid(rb_pid_t pid, int *stat_loc, int options)
int _cdecl
gettimeofday(struct timeval *tv, struct timezone *tz)
{
- SYSTEMTIME st;
- struct tm tm;
-
- GetSystemTime(&st);
- time(&tv->tv_sec);
- tv->tv_usec = st.wMilliseconds * 1000;
+ FILETIME ft;
+ ULARGE_INTEGER tmp;
+ unsigned LONG_LONG lt;
+
+ GetSystemTimeAsFileTime(&ft);
+ tmp.LowPart = ft.dwLowDateTime;
+ tmp.HighPart = ft.dwHighDateTime;
+ lt = tmp.QuadPart;
+
+ /* lt is now 100-nanosec intervals since 1601/01/01 00:00:00 UTC,
+ convert it into UNIX time (since 1970/01/01 00:00:00 UTC).
+ the first leap second is at 1972/06/30, so we doesn't need to think
+ about it. */
+ lt /= 10000; /* to msec */
+ lt -= (LONG_LONG)(369 * 365 + 24 * 3 + 17) * 24 * 60 * 60 * 1000;
+
+ tv->tv_sec = lt / 1000;
+ tv->tv_usec = lt % 1000;
return 0;
}