mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-22 16:04:25 +00:00
indexer: mmap fixes for Windows
Windows has its own ftruncate() called _chsize_s(). p_mkstemp() is changed to use p_open() so we can make sure we open for writing; the addition of exclusive create is a good thing to do regardless, as we want a temporary path for ourselves. Lastly, MSVC doesn't quite know how to add two numbers if one of them is a void pointer, so let's alias it to unsigned char.C
This commit is contained in:
parent
f7310540ae
commit
0731a5b4db
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user