diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h index f4841fb..3b4d2bd 100644 --- a/src/include/port/win32_port.h +++ b/src/include/port/win32_port.h @@ -52,7 +52,19 @@ #include #include /* for non-unicode version */ #undef near +/* + * We need to define _CRT_NO_TIME_T in order to prevent the definition of + * struct stat and replace it with struct _stat64 + */ +#if defined(_MSC_VER) +#define HAVE_STRUCT_STAT64 +#define _CRT_NO_TIME_T +#include +#include +#undef _CRT_NO_TIME_T +#else #include /* needed before sys/stat hacking below */ +#endif /* Must be here to avoid conflicting with prototype in windows.h */ #define mkdir(a,b) mkdir(a) @@ -251,6 +263,34 @@ typedef int pid_t; * We must pull in sys/stat.h before this part, else our overrides lose. */ #define lstat(path, sb) stat(path, sb) +#if defined(HAVE_STRUCT_STAT64) +struct stat /* It is actually _stat64 */ +{ + _dev_t st_dev; + _ino_t st_ino; + unsigned short st_mode; + short st_nlink; + short st_uid; + short st_gid; + _dev_t st_rdev; + __int64 st_size; + __time64_t st_atime; + __time64_t st_mtime; + __time64_t st_ctime; +}; +static __inline int +fstat(int const _FileName, struct stat* const _Stat) +{ + Assert(sizeof(struct stat) == sizeof(struct _stat64)); + return _fstat64(_FileName, (struct _stat64*)_Stat); +} +static __inline int +stat(char const* const _FileName, struct stat* const _Stat) +{ + Assert(sizeof(struct stat) == sizeof(struct _stat64)); + return _stat64(_FileName, (struct _stat64*)_Stat); +} +#endif /* * stat() is not guaranteed to set the st_size field on win32, so we diff --git a/src/port/dirmod.c b/src/port/dirmod.c index d793240..01cb85d 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -395,11 +395,10 @@ pgwin32_safestat(const char *path, struct stat *buf) return -1; } - /* - * XXX no support for large files here, but we don't do that in general on - * Win32 yet. - */ - buf->st_size = attr.nFileSizeLow; + if (sizeof(buf->st_size) < sizeof(uint64)) + buf->st_size = attr.nFileSizeLow; + else + buf->st_size = ((uint64) attr.nFileSizeHigh) << 32 | attr.nFileSizeLow; return 0; }