aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-02 01:17:28 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-02 01:17:28 +0000
commit0c26c309d47c50699990972ddb356db4afcde324 (patch)
tree1b27f1365a1f190e20bceb51221a456048558c07
parent784ccb5806051c0fc66cc1ab12ed3ca94a1bd0ed (diff)
downloadruby-0c26c309d47c50699990972ddb356db4afcde324.tar.gz
* 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/trunk@19049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--win32/win32.c24
2 files changed, 23 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 454cf66d64..f7b8447d96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Sep 2 10:09:17 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/win32.c (gettimeofday): calc tv_sec and tv_usec from system
+ time by myself. [ruby-dev:36084]
+
Tue Sep 2 04:00:37 2008 Tanaka Akira <akr@fsij.org>
* transcode_data.h (o3): prevent sign extension on 64bit environment.
diff --git a/win32/win32.c b/win32/win32.c
index 3c551cae04..4239a4a3fc 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3088,12 +3088,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;
}