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

ruby-changes:23059

From: nobu <ko1@a...>
Date: Thu, 22 Mar 2012 19:55:20 +0900 (JST)
Subject: [ruby-changes:23059] nobu:r35109 (trunk): * win32/win32.c (rb_w32_fstat, rb_w32_fstati64): convert FILETIME

nobu	2012-03-22 19:55:11 +0900 (Thu, 22 Mar 2012)

  New Revision: 35109

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

  Log:
    * win32/win32.c (rb_w32_fstat, rb_w32_fstati64): convert FILETIME
      to time_t directly, not to be affected by TZ unnecessarily.
    * win32/win32.c (unixtime_to_filetime): convert time_t to FILETIME
      simply.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/win32.h
    trunk/win32/win32.c

Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h	(revision 35108)
+++ include/ruby/win32.h	(revision 35109)
@@ -150,6 +150,7 @@
 #define getppid()		rb_w32_getppid()
 #define sleep(x)		rb_w32_Sleep((x)*1000)
 #define Sleep(msec)		(void)rb_w32_Sleep(msec)
+#define _fstati64(fd,st)	rb_w32_fstati64(fd,st)
 #ifdef __BORLANDC__
 #define creat(p, m)		_creat(p, m)
 #define eof()			_eof()
@@ -158,7 +159,6 @@
 #define tell(h)			_tell(h)
 #define _open			_sopen
 #define sopen			_sopen
-#define _fstati64(fd,st)	rb_w32_fstati64(fd,st)
 #undef fopen
 #define fopen(p, m)		rb_w32_fopen(p, m)
 #undef fdopen
@@ -306,9 +306,9 @@
 extern int rb_w32_access(const char *, int);
 extern int rb_w32_uaccess(const char *, int);
 extern char rb_w32_fd_is_text(int);
+extern int rb_w32_fstati64(int, struct stati64 *);
 
 #ifdef __BORLANDC__
-extern int rb_w32_fstati64(int, struct stati64 *);
 extern off_t _lseeki64(int, off_t, int);
 extern FILE *rb_w32_fopen(const char *, const char *);
 extern FILE *rb_w32_fdopen(int, const char *);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35108)
+++ ChangeLog	(revision 35109)
@@ -1,3 +1,11 @@
+Thu Mar 22 19:55:08 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (rb_w32_fstat, rb_w32_fstati64): convert FILETIME
+	  to time_t directly, not to be affected by TZ unnecessarily.
+
+	* win32/win32.c (unixtime_to_filetime): convert time_t to FILETIME
+	  simply.
+
 Thu Mar 22 13:43:31 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/openssl/ossl_pkey_rsa.c (rsa_generate): fix argument type.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 35108)
+++ win32/win32.c	(revision 35109)
@@ -4433,7 +4433,8 @@
 	(dest).st_ctime = (src).st_ctime;	\
     } while (0)
 
-#ifdef __BORLANDC__
+static time_t filetime_to_unixtime(const FILETIME *ft);
+
 #undef fstat
 /* License: Ruby's */
 int
@@ -4443,10 +4444,18 @@
     int ret = fstat(fd, st);
 
     if (ret) return ret;
+#ifdef __BORLANDC__
     st->st_mode &= ~(S_IWGRP | S_IWOTH);
-    if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info) &&
-	!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
-	st->st_mode |= S_IWUSR;
+#endif
+    if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) {
+#ifdef __BORLANDC__
+	if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
+	    st->st_mode |= S_IWUSR;
+	}
+#endif
+	st->st_atime = filetime_to_unixtime(&info.ftLastAccessTime);
+	st->st_mtime = filetime_to_unixtime(&info.ftLastWriteTime);
+	st->st_ctime = filetime_to_unixtime(&info.ftCreationTime);
     }
     return ret;
 }
@@ -4460,17 +4469,23 @@
     int ret = fstat(fd, &tmp);
 
     if (ret) return ret;
+#ifdef __BORLANDC__
     tmp.st_mode &= ~(S_IWGRP | S_IWOTH);
+#endif
     COPY_STAT(tmp, *st, +);
     if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) {
+#ifdef __BORLANDC__
 	if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
 	    st->st_mode |= S_IWUSR;
 	}
+#endif
 	st->st_size = ((__int64)info.nFileSizeHigh << 32) | info.nFileSizeLow;
+	st->st_atime = filetime_to_unixtime(&info.ftLastAccessTime);
+	st->st_mtime = filetime_to_unixtime(&info.ftLastWriteTime);
+	st->st_ctime = filetime_to_unixtime(&info.ftCreationTime);
     }
     return ret;
 }
-#endif
 
 /* License: Ruby's */
 static time_t
@@ -5817,27 +5832,11 @@
 static int
 unixtime_to_filetime(time_t time, FILETIME *ft)
 {
-    struct tm *tm;
-    SYSTEMTIME st;
-    FILETIME lt;
+    ULARGE_INTEGER tmp;
 
-    tm = localtime(&time);
-    if (!tm) {
-	return -1;
-    }
-    st.wYear = tm->tm_year + 1900;
-    st.wMonth = tm->tm_mon + 1;
-    st.wDayOfWeek = tm->tm_wday;
-    st.wDay = tm->tm_mday;
-    st.wHour = tm->tm_hour;
-    st.wMinute = tm->tm_min;
-    st.wSecond = tm->tm_sec;
-    st.wMilliseconds = 0;
-    if (!SystemTimeToFileTime(&st, &lt) ||
-	!LocalFileTimeToFileTime(&lt, ft)) {
-	errno = map_errno(GetLastError());
-	return -1;
-    }
+    tmp.QuadPart = ((LONG_LONG)time + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000;
+    ft->dwLowDateTime = tmp.LowPart;
+    ft->dwHighDateTime = tmp.HighPart;
     return 0;
 }
 

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

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