Commit 8be12026a158f0836c73f6b9f33abab640d9a115

Edward Thomson 2019-06-23T17:09:22

mmap: use a 64-bit signed type `off64_t` for mmap Prefer `off64_t` to `git_off_t` for internal visibility.

diff --git a/src/futils.c b/src/futils.c
index 7e100a9..a7c360a 100644
--- a/src/futils.c
+++ b/src/futils.c
@@ -307,7 +307,7 @@ int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmod
 	return 0;
 }
 
-int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
+int git_futils_mmap_ro(git_map *out, git_file fd, off64_t begin, size_t len)
 {
 	return p_mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin);
 }
diff --git a/src/futils.h b/src/futils.h
index f97b156..3d56646 100644
--- a/src/futils.h
+++ b/src/futils.h
@@ -290,7 +290,7 @@ extern mode_t git_futils_canonical_mode(mode_t raw_mode);
 extern int git_futils_mmap_ro(
 	git_map *out,
 	git_file fd,
-	git_off_t begin,
+	off64_t begin,
 	size_t len);
 
 /**
diff --git a/src/map.h b/src/map.h
index 2009c3a..6328d8c 100644
--- a/src/map.h
+++ b/src/map.h
@@ -40,7 +40,7 @@ typedef struct { /* memory mapped buffer	*/
 	assert((prot & GIT_PROT_WRITE) || (prot & GIT_PROT_READ)); \
 	assert((flags & GIT_MAP_FIXED) == 0); } while (0)
 
-extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset);
+extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset);
 extern int p_munmap(git_map *map);
 
 #endif
diff --git a/src/posix.c b/src/posix.c
index 1ea2ce5..fbaa7c3 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -235,7 +235,7 @@ int git__mmap_alignment(size_t *alignment)
 }
 
 
-int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset)
 {
 	GIT_MMAP_VALIDATE(out, len, prot, flags);
 
diff --git a/src/posix.h b/src/posix.h
index 170ff26..eef6677 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -89,6 +89,18 @@
 #define EAFNOSUPPORT (INT_MAX-1)
 #endif
 
+/* Provide a 64-bit size for offsets. */
+
+#if defined(_MSC_VER)
+typedef __int64 off64_t;
+#elif defined(__HAIKU__)
+typedef __haiku_std_int64 off64_t;
+#elif defined(__APPLE__)
+typedef __int64_t off64_t;
+#else
+typedef int64_t off64_t;
+#endif
+
 typedef int git_file;
 
 /**
diff --git a/src/win32/map.c b/src/win32/map.c
index dff0695..e2ce737 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -50,7 +50,7 @@ int git__mmap_alignment(size_t *page_size)
 	return 0;
 }
 
-int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset)
 {
 	HANDLE fh = (HANDLE)_get_osfhandle(fd);
 	DWORD alignment = get_allocation_granularity();
@@ -58,8 +58,8 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
 	DWORD view_prot = 0;
 	DWORD off_low = 0;
 	DWORD off_hi = 0;
-	git_off_t page_start;
-	git_off_t page_offset;
+	off64_t page_start;
+	off64_t page_offset;
 
 	GIT_MMAP_VALIDATE(out, len, prot, flags);