summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>2010-01-11 19:27:50 +0000
committerRamsay Jones <ramsay@ramsay1.demon.co.uk>2010-01-20 20:15:57 +0000
commit90d4d2f0fc362beabbbf76b4ffda0828229c198d (patch)
tree0f6d2f4cd1a1391a98c6a89e2ee6a69c0afc0c9d
parenta1c0728d12b170e1e643f219fab53b03cd4e1b09 (diff)
downloadlibgit2-90d4d2f0fc362beabbbf76b4ffda0828229c198d.tar.gz
win32: Use an 64-bit file offset type
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
-rw-r--r--src/common.h18
-rw-r--r--src/fileops.c12
-rw-r--r--src/fileops.h1
-rw-r--r--src/win32/map.c4
4 files changed, 29 insertions, 6 deletions
diff --git a/src/common.h b/src/common.h
index 35df53402..29a61a7f8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -25,6 +25,7 @@
#include <string.h>
#include <sys/types.h>
+#include <sys/stat.h>
#ifdef GIT_WIN32
@@ -51,6 +52,23 @@ typedef SSIZE_T ssize_t;
# define R_OK 4 /* read mode check */
# endif
+#if defined(__MINGW32__)
+
+# define off_t off64_t
+# define lseek _lseeki64
+# define stat _stati64
+# define fstat _fstati64
+
+#elif defined(_MSC_VER)
+
+typedef __int64 off64_t;
+# define off_t off64_t
+# define lseek _lseeki64
+# define stat _stat64
+# define fstat _fstat64
+
+#endif
+
#else
# include <unistd.h>
diff --git a/src/fileops.c b/src/fileops.c
index 5de89cbd8..b2dea1ed6 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -69,7 +69,8 @@ off_t gitfo_size(git_file fd)
int gitfo_read_file(gitfo_buf *obj, const char *path)
{
git_file fd;
- off_t len;
+ size_t len;
+ off_t size;
unsigned char *buff;
assert(obj && path && *path);
@@ -77,8 +78,13 @@ int gitfo_read_file(gitfo_buf *obj, const char *path)
if ((fd = gitfo_open(path, O_RDONLY)) < 0)
return GIT_ERROR;
- if (((len = gitfo_size(fd)) < 0)
- || ((buff = git__malloc(len + 1)) == NULL)) {
+ if (((size = gitfo_size(fd)) < 0) || !git__is_sizet(size+1)) {
+ gitfo_close(fd);
+ return GIT_ERROR;
+ }
+ len = (size_t) size;
+
+ if ((buff = git__malloc(len + 1)) == NULL) {
gitfo_close(fd);
return GIT_ERROR;
}
diff --git a/src/fileops.h b/src/fileops.h
index 98fffeb84..b5cc24e62 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -9,7 +9,6 @@
#include "common.h"
#include "map.h"
#include "dir.h"
-#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
diff --git a/src/win32/map.c b/src/win32/map.c
index 7d685c722..388e9c621 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -77,9 +77,9 @@ int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, off_t offse
return GIT_ERROR;
}
+ assert(sizeof(off_t) == 8);
off_low = (DWORD)(page_start);
- if (sizeof(off_t) > 4)
- off_hi = (DWORD)(page_start >> 32);
+ off_hi = (DWORD)(page_start >> 32);
out->data = MapViewOfFile(out->fmh, view_prot, off_hi, off_low, len);
if (!out->data) {
/* errno = ? */