[前][次][番号順一覧][スレッド一覧]

ruby-changes:7960

From: usa <ko1@a...>
Date: Tue, 23 Sep 2008 19:31:07 +0900 (JST)
Subject: [ruby-changes:7960] Ruby:r19482 (ruby_1_8): * win32/win32.c (filetime_to_timeval): new function, split from

usa	2008-09-23 19:30:53 +0900 (Tue, 23 Sep 2008)

  New Revision: 19482

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19482

  Log:
    * 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]

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/win32/win32.c

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 19481)
+++ ruby_1_8/ChangeLog	(revision 19482)
@@ -1,3 +1,12 @@
+Tue Sep 23 19:30:41 2008  NAKAMURA Usaku  <usa@r...>
+
+	* 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  <nobu@r...>
 
 	* hash.c (ENVMATCH, ENVNMATCH): reduced same code.
Index: ruby_1_8/win32/win32.c
===================================================================
--- ruby_1_8/win32/win32.c	(revision 19481)
+++ ruby_1_8/win32/win32.c	(revision 19482)
@@ -2975,16 +2975,14 @@
 
 #include <sys/timeb.h>
 
-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 @@
     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 @@
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]