diff options
-rw-r--r-- | src/indexer.c | 4 | ||||
-rw-r--r-- | src/posix.h | 2 | ||||
-rw-r--r-- | src/win32/posix.h | 6 | ||||
-rw-r--r-- | src/win32/posix_w32.c | 2 |
4 files changed, 11 insertions, 3 deletions
diff --git a/src/indexer.c b/src/indexer.c index 11268e018..ebfdffb47 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -429,6 +429,7 @@ static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t git_file fd = idx->pack->mwf.fd; long page_size = git__page_size(); git_off_t page_start, page_offset; + unsigned char *map_data; git_map map; int error; @@ -439,7 +440,8 @@ static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t if ((error = p_mmap(&map, page_offset + size, GIT_PROT_WRITE, GIT_MAP_SHARED, fd, page_start)) < 0) return error; - memcpy(map.data + page_offset, data, size); + map_data = (unsigned char *)map.data; + memcpy(map_data + page_offset, data, size); p_munmap(&map); return 0; diff --git a/src/posix.h b/src/posix.h index 745e4af75..965cd98d5 100644 --- a/src/posix.h +++ b/src/posix.h @@ -60,7 +60,6 @@ extern int p_write(git_file fd, const void *buf, size_t cnt); #define p_lseek(f,n,w) lseek(f, n, w) #define p_close(fd) close(fd) #define p_umask(m) umask(m) -#define p_ftruncate(fd, sz) ftruncate(fd, sz) extern int p_open(const char *path, int flags, ...); extern int p_creat(const char *path, mode_t mode); @@ -74,6 +73,7 @@ extern int p_rename(const char *from, const char *to); #define p_rmdir(p) rmdir(p) #define p_chmod(p,m) chmod(p, m) #define p_access(p,m) access(p,m) +#define p_ftruncate(fd, sz) ftruncate(fd, sz) #define p_recv(s,b,l,f) recv(s,b,l,f) #define p_send(s,b,l,f) send(s,b,l,f) typedef int GIT_SOCKET; diff --git a/src/win32/posix.h b/src/win32/posix.h index 7f9d57cc3..2cbea1807 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -19,6 +19,12 @@ # define EAFNOSUPPORT (INT_MAX-1) #endif +#ifdef _MSC_VER +# define p_ftruncate(fd, sz) _chsize_s(fd, sz) +#else /* MinGW */ +# define p_ftruncate(fd, sz) _chsize(fd, sz) +#endif + GIT_INLINE(int) p_link(const char *old, const char *new) { GIT_UNUSED(old); diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 73bf92572..34938431a 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -578,7 +578,7 @@ int p_mkstemp(char *tmp_path) return -1; #endif - return p_creat(tmp_path, 0744); //-V536 + return p_open(tmp_path, O_RDWR | O_CREAT | O_EXCL, 0744); //-V536 } int p_access(const char* path, mode_t mode) |