summaryrefslogtreecommitdiff
path: root/win32.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-08-10 09:10:41 +0000
committerDarkvater <Darkvater@openttd.org>2006-08-10 09:10:41 +0000
commit1f006f20620d02633b37ce3cc3808ecd3b6bcc0c (patch)
treeed6fd7cde73f05a4201dbacc2482a4c2708120be /win32.c
parent8048e8c5bd4ab015715fbdb616c3b7306b396ff0 (diff)
downloadopenttd-1f006f20620d02633b37ce3cc3808ecd3b6bcc0c.tar.xz
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Diffstat (limited to 'win32.c')
-rw-r--r--win32.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/win32.c b/win32.c
index d12cf1aec..0f789dbfa 100644
--- a/win32.c
+++ b/win32.c
@@ -719,11 +719,18 @@ void FiosGetDrives(void)
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
{
+ // hectonanoseconds between Windows and POSIX epoch
+ static const int64 posix_epoch_hns = 0x019DB1DED53E8000;
const WIN32_FIND_DATA *fd = &ent->dir->fd;
if (fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) return false;
sb->st_size = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow;
- sb->st_mtime = *(uint64*)&fd->ftLastWriteTime;
+ /* UTC FILETIME to seconds-since-1970 UTC
+ * we just have to subtract POSIX epoch and scale down to units of seconds.
+ * http://www.gamedev.net/community/forums/topic.asp?topic_id=294070&whichpage=1&#1860504
+ * XXX - not entirely correct, since filetimes on FAT aren't UTC but local,
+ * this won't entirely be correct, but we use the time only for comparsion. */
+ sb->st_mtime = (time_t)((*(uint64*)&fd->ftLastWriteTime - posix_epoch_hns) / 1E7);
sb->st_mode = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG;
return true;