summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-17 15:04:57 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-17 15:04:57 +0000
commit9310a593df470eccac1068f2a70e8707655ec21d (patch)
tree7d21728599db73aec1eb7d2d9304fe861d811530 /win32
parent6c29b79807253217c70172260f999c40b26dc49d (diff)
merge revision(s) 35109,35110,35651: [Backport #6385]
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 6ea6888e10..e7545fe17a 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4131,7 +4131,8 @@ isUNCRoot(const WCHAR *path)
(dest).st_ctime = (src).st_ctime; \
} while (0)
-#ifdef __BORLANDC__
+static time_t filetime_to_unixtime(const FILETIME *ft);
+
#undef fstat
int
rb_w32_fstat(int fd, struct stat *st)
@@ -4140,10 +4141,18 @@ rb_w32_fstat(int fd, struct stat *st)
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;
}
@@ -4156,17 +4165,23 @@ rb_w32_fstati64(int fd, struct stati64 *st)
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
static time_t
filetime_to_unixtime(const FILETIME *ft)
@@ -5456,27 +5471,11 @@ rb_w32_write_console(uintptr_t strarg, int fd)
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;
}