Skip to content

Commit 1d4e4cd

Browse files
dschogitster
authored andcommitted
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>
1 parent fad5c96 commit 1d4e4cd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

compat/mingw.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ static int do_lstat(const char *file_name, struct stat *buf)
4646
buf->st_uid = 0;
4747
buf->st_nlink = 1;
4848
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);
5051
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
5152
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
5253
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
@@ -101,15 +102,16 @@ int mingw_fstat(int fd, struct stat *buf)
101102
}
102103
/* direct non-file handles to MS's fstat() */
103104
if (GetFileType(fh) != FILE_TYPE_DISK)
104-
return fstat(fd, buf);
105+
return _fstati64(fd, buf);
105106

106107
if (GetFileInformationByHandle(fh, &fdata)) {
107108
buf->st_ino = 0;
108109
buf->st_gid = 0;
109110
buf->st_uid = 0;
110111
buf->st_nlink = 1;
111112
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);
113115
buf->st_dev = buf->st_rdev = 0; /* not used by Git */
114116
buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
115117
buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));

compat/mingw.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,14 @@ int mingw_rename(const char*, const char*);
163163
/* Use mingw_lstat() instead of lstat()/stat() and
164164
* mingw_fstat() instead of fstat() on Windows.
165165
*/
166+
#define off_t off64_t
167+
#define stat _stati64
168+
#define lseek _lseeki64
166169
int mingw_lstat(const char *file_name, struct stat *buf);
167170
int mingw_fstat(int fd, struct stat *buf);
168171
#define fstat mingw_fstat
169172
#define lstat mingw_lstat
170-
#define stat(x,y) mingw_lstat(x,y)
173+
#define stat64(x,y) mingw_lstat(x,y)
171174

172175
int mingw_utime(const char *file_name, const struct utimbuf *times);
173176
#define utime mingw_utime

0 commit comments

Comments
 (0)