* 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
This commit is contained in:
usa 2008-09-02 01:19:07 +00:00
parent ea75c908dc
commit d1f4a0fafa
2 changed files with 22 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Tue Sep 2 10:18:58 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]
Mon Sep 1 18:31:10 2008 NAKAMURA Usaku <usa@ruby-lang.org> Mon Sep 1 18:31:10 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (gettimeofday): shouldn't use mktime(3) because it's * win32/win32.c (gettimeofday): shouldn't use mktime(3) because it's

View file

@ -2978,12 +2978,24 @@ waitpid(rb_pid_t pid, int *stat_loc, int options)
int _cdecl int _cdecl
gettimeofday(struct timeval *tv, struct timezone *tz) gettimeofday(struct timeval *tv, struct timezone *tz)
{ {
SYSTEMTIME st; FILETIME ft;
struct tm tm; ULARGE_INTEGER tmp;
unsigned LONG_LONG lt;
GetSystemTime(&st); GetSystemTimeAsFileTime(&ft);
time(&tv->tv_sec); tmp.LowPart = ft.dwLowDateTime;
tv->tv_usec = st.wMilliseconds * 1000; 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; return 0;
} }