ruby-changes:7530
From: usa <ko1@a...>
Date: Tue, 2 Sep 2008 10:19:20 +0900 (JST)
Subject: [ruby-changes:7530] Ruby:r19050 (ruby_1_8): * win32/win32.c (gettimeofday): calc tv_sec and tv_usec from system
usa 2008-09-02 10:19:07 +0900 (Tue, 02 Sep 2008) New Revision: 19050 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19050 Log: * win32/win32.c (gettimeofday): calc tv_sec and tv_usec from system time by myself. [ruby-dev:36084] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/win32/win32.c Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 19049) +++ ruby_1_8/ChangeLog (revision 19050) @@ -1,3 +1,8 @@ +Tue Sep 2 10:18:58 2008 NAKAMURA Usaku <usa@r...> + + * win32/win32.c (gettimeofday): calc tv_sec and tv_usec from system + time by myself. [ruby-dev:36084] + Mon Sep 1 18:31:10 2008 NAKAMURA Usaku <usa@r...> * win32/win32.c (gettimeofday): shouldn't use mktime(3) because it's Index: ruby_1_8/win32/win32.c =================================================================== --- ruby_1_8/win32/win32.c (revision 19049) +++ ruby_1_8/win32/win32.c (revision 19050) @@ -2978,13 +2978,25 @@ int _cdecl gettimeofday(struct timeval *tv, struct timezone *tz) { - SYSTEMTIME st; - struct tm tm; + FILETIME ft; + ULARGE_INTEGER tmp; + unsigned LONG_LONG lt; - GetSystemTime(&st); - time(&tv->tv_sec); - tv->tv_usec = st.wMilliseconds * 1000; + 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; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/