From c0e0e87b45a29c2f2e5a802dd7533994ee34dd8d Mon Sep 17 00:00:00 2001 From: usa Date: Tue, 23 Sep 2008 10:30:53 +0000 Subject: [PATCH] * win32/win32.c (filetime_to_timeval): new function, split from gettimeofday(). * win32/win32.c (gettimeofday): use above function. * win32/win32.c (filetime_to_unixtime): ditto. [ruby-dev:36135] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@19482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ win32/win32.c | 44 +++++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index df6b823523..62948e94d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Sep 23 19:30:41 2008 NAKAMURA Usaku + + * win32/win32.c (filetime_to_timeval): new function, split from + gettimeofday(). + + * win32/win32.c (gettimeofday): use above function. + + * win32/win32.c (filetime_to_unixtime): ditto. [ruby-dev:36135] + Tue Sep 23 16:59:45 2008 Nobuyoshi Nakada * hash.c (ENVMATCH, ENVNMATCH): reduced same code. diff --git a/win32/win32.c b/win32/win32.c index 02b22cee9b..6bd5a0694e 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2975,16 +2975,14 @@ waitpid(rb_pid_t pid, int *stat_loc, int options) #include -int _cdecl -gettimeofday(struct timeval *tv, struct timezone *tz) +static int +filetime_to_timeval(const FILETIME* ft, struct timeval *tv) { - FILETIME ft; ULARGE_INTEGER tmp; unsigned LONG_LONG lt; - GetSystemTimeAsFileTime(&ft); - tmp.LowPart = ft.dwLowDateTime; - tmp.HighPart = ft.dwHighDateTime; + 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, @@ -2997,6 +2995,17 @@ gettimeofday(struct timeval *tv, struct timezone *tz) tv->tv_sec = lt / (1000 * 1000); tv->tv_usec = lt % (1000 * 1000); + return tv->tv_sec > 0 ? 0 : -1; +} + +int _cdecl +gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; + + GetSystemTimeAsFileTime(&ft); + filetime_to_timeval(&ft, tv); + return 0; } @@ -3270,27 +3279,12 @@ isUNCRoot(const char *path) static time_t filetime_to_unixtime(const FILETIME *ft) { - FILETIME loc; - SYSTEMTIME st; - struct tm tm; - time_t t; + struct timeval tv; - if (!FileTimeToLocalFileTime(ft, &loc)) { + if (filetime_to_timeval(ft, &tv) == (time_t)-1) return 0; - } - if (!FileTimeToSystemTime(&loc, &st)) { - return 0; - } - memset(&tm, 0, sizeof(tm)); - tm.tm_year = st.wYear - 1900; - tm.tm_mon = st.wMonth - 1; - tm.tm_mday = st.wDay; - tm.tm_hour = st.wHour; - tm.tm_min = st.wMinute; - tm.tm_sec = st.wSecond; - tm.tm_isdst = -1; - t = mktime(&tm); - return t == -1 ? 0 : t; + else + return tv.tv_sec; } static unsigned