@matheusbsbs / matheus-bagliano / commits / 1d4e4cd4a1
Fork 0

MinGW: 64-bit file offsets

The type 'off_t' should be used everywhere so that the bit-depth of that type can be adjusted in the standard C library, and you just need to recompile your program to benefit from the extended precision. Only that it was not done that way in the MS runtime library. This patch reroutes off_t to off64_t and provides the other necessary changes so that finally, clones larger than 2 gigabyte work on Windows (provided you are on a file system that allows files larger than 2gb). Initial patch by Sickboy <sb@dev-heaven.net>. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Mar 5, 2009 at 17:05 UTC 1d4e4cd4a108dc105f6c8e739c69b9261d4e92a5
2 files changed +9 -4
compat/mingw.c
+5 -3
@@ -46,7 +46,8 @@ static int do_lstat(const char *file_name, struct stat *buf)
46 buf->st_uid = 0;
47 buf->st_nlink = 1;
48 buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
49 - buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
49 + buf->st_size = fdata.nFileSizeLow |
50 + (((off_t)fdata.nFileSizeHigh)<<32);
51 buf->st_dev = buf->st_rdev = 0; /* not used by Git */
52 buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
53 buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
@@ -101,7 +102,7 @@ int mingw_fstat(int fd, struct stat *buf)
102 }
103 /* direct non-file handles to MS's fstat() */
104 if (GetFileType(fh) != FILE_TYPE_DISK)
104 - return fstat(fd, buf);
105 + return _fstati64(fd, buf);
106
107 if (GetFileInformationByHandle(fh, &fdata)) {
108 buf->st_ino = 0;
@@ -109,7 +110,8 @@ int mingw_fstat(int fd, struct stat *buf)
110 buf->st_uid = 0;
111 buf->st_nlink = 1;
112 buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes);
112 - buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */
113 + buf->st_size = fdata.nFileSizeLow |
114 + (((off_t)fdata.nFileSizeHigh)<<32);
115 buf->st_dev = buf->st_rdev = 0; /* not used by Git */
116 buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
117 buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
compat/mingw.h
+4 -1
@@ -163,11 +163,14 @@ int mingw_rename(const char*, const char*);
163 /* Use mingw_lstat() instead of lstat()/stat() and
164 * mingw_fstat() instead of fstat() on Windows.
165 */
166 +#define off_t off64_t
167 +#define stat _stati64
168 +#define lseek _lseeki64
169 int mingw_lstat(const char *file_name, struct stat *buf);
170 int mingw_fstat(int fd, struct stat *buf);
171 #define fstat mingw_fstat
172 #define lstat mingw_lstat
170 -#define stat(x,y) mingw_lstat(x,y)
173 +#define stat64(x,y) mingw_lstat(x,y)
174
175 int mingw_utime(const char *file_name, const struct utimbuf *times);
176 #define utime mingw_utime