win32.c
changeset 4245 59697b49326e
parent 4236 1bc9b3024d0d
child 4247 00cdac3de8e9
equal deleted inserted replaced
4244:44dcec623504 4245:59697b49326e
   717 	}
   717 	}
   718 }
   718 }
   719 
   719 
   720 bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
   720 bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
   721 {
   721 {
       
   722 	// hectonanoseconds between Windows and POSIX epoch
       
   723 	static const int64 posix_epoch_hns = 0x019DB1DED53E8000;
   722 	const WIN32_FIND_DATA *fd = &ent->dir->fd;
   724 	const WIN32_FIND_DATA *fd = &ent->dir->fd;
   723 	if (fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) return false;
   725 	if (fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) return false;
   724 
   726 
   725 	sb->st_size  = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow;
   727 	sb->st_size  = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow;
   726 	sb->st_mtime = *(uint64*)&fd->ftLastWriteTime;
   728 	/* UTC FILETIME to seconds-since-1970 UTC
       
   729 	 * we just have to subtract POSIX epoch and scale down to units of seconds.
       
   730 	 * http://www.gamedev.net/community/forums/topic.asp?topic_id=294070&whichpage=1&#1860504
       
   731 	 * XXX - not entirely correct, since filetimes on FAT aren't UTC but local,
       
   732 	 * this won't entirely be correct, but we use the time only for comparsion. */
       
   733 	sb->st_mtime = (time_t)((*(uint64*)&fd->ftLastWriteTime - posix_epoch_hns) / 1E7);
   727 	sb->st_mode  = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG;
   734 	sb->st_mode  = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG;
   728 
   735 
   729 	return true;
   736 	return true;
   730 }
   737 }
   731 
   738