mmap: use a 64-bit signed type `off64_t` for mmap Prefer `off64_t` to `git_off_t` for internal visibility.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
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);