summaryrefslogtreecommitdiff
path: root/src/win32
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-05-14 19:12:48 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-05-17 01:39:43 +0200
commit0731a5b4db086eefac1a842e37526ef7bdbaa7de (patch)
tree8de449f06fae5e819e750ae7ae0f29cfe33574e6 /src/win32
parentf7310540ae888454f9ab69200cfcd8df07faf957 (diff)
downloadlibgit2-0731a5b4db086eefac1a842e37526ef7bdbaa7de.tar.gz
indexer: mmap fixes for Windowscmn/indexer-mmap
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
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/posix.h6
-rw-r--r--src/win32/posix_w32.c2
2 files changed, 7 insertions, 1 deletions
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)