* 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/trunk@19106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9b6608c78d
commit
e64711977b
@ -1,3 +1,12 @@
|
|||||||
|
Thu Sep 4 01:12:03 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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]
|
||||||
|
|
||||||
Thu Sep 4 01:00:57 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
Thu Sep 4 01:00:57 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* transcode.c (transcode_restartable0): avoid VC++6's bug.
|
* transcode.c (transcode_restartable0): avoid VC++6's bug.
|
||||||
|
@ -3086,27 +3086,36 @@ waitpid(rb_pid_t pid, int *stat_loc, int options)
|
|||||||
|
|
||||||
#include <sys/timeb.h>
|
#include <sys/timeb.h>
|
||||||
|
|
||||||
int _cdecl
|
static int
|
||||||
gettimeofday(struct timeval *tv, struct timezone *tz)
|
filetime_to_timeval(const FILETIME* ft, struct timeval *tv)
|
||||||
{
|
{
|
||||||
FILETIME ft;
|
|
||||||
ULARGE_INTEGER tmp;
|
ULARGE_INTEGER tmp;
|
||||||
unsigned LONG_LONG lt;
|
unsigned LONG_LONG lt;
|
||||||
|
|
||||||
GetSystemTimeAsFileTime(&ft);
|
tmp.LowPart = ft->dwLowDateTime;
|
||||||
tmp.LowPart = ft.dwLowDateTime;
|
tmp.HighPart = ft->dwHighDateTime;
|
||||||
tmp.HighPart = ft.dwHighDateTime;
|
|
||||||
lt = tmp.QuadPart;
|
lt = tmp.QuadPart;
|
||||||
|
|
||||||
/* lt is now 100-nanosec intervals since 1601/01/01 00:00:00 UTC,
|
/* 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).
|
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
|
the first leap second is at 1972/06/30, so we doesn't need to think
|
||||||
about it. */
|
about it. */
|
||||||
lt /= 10000; /* to msec */
|
lt /= 10; /* to usec */
|
||||||
lt -= (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60 * 1000;
|
lt -= (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60 * 1000 * 1000;
|
||||||
|
|
||||||
tv->tv_sec = lt / 1000;
|
tv->tv_sec = lt / (1000 * 1000);
|
||||||
tv->tv_usec = lt % 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;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -3432,26 +3441,12 @@ static time_t
|
|||||||
filetime_to_unixtime(const FILETIME *ft)
|
filetime_to_unixtime(const FILETIME *ft)
|
||||||
{
|
{
|
||||||
FILETIME loc;
|
FILETIME loc;
|
||||||
SYSTEMTIME st;
|
struct timeval tv;
|
||||||
struct tm tm;
|
|
||||||
time_t t;
|
|
||||||
|
|
||||||
if (!FileTimeToLocalFileTime(ft, &loc)) {
|
if (filetime_to_timeval(ft, &tv) == (time_t)-1)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
else
|
||||||
if (!FileTimeToSystemTime(&loc, &st)) {
|
return tv.tv_sec;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
|
Loading…
x
Reference in New Issue
Block a user