summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/posix.c17
-rw-r--r--src/posix.h1
-rw-r--r--src/win32/posix_w32.c6
3 files changed, 24 insertions, 0 deletions
diff --git a/src/posix.c b/src/posix.c
index bffe02e05..ef48c6012 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -216,6 +216,23 @@ int p_write(git_file fd, const void *buf, size_t cnt)
return 0;
}
+int p_fallocate(int fd, off_t offset, off_t len)
+{
+#ifdef __APPLE__
+ fstore_t prealloc;
+
+ memset(&prealloc, 0, sizeof(prealloc));
+ prealloc.fst_flags = F_ALLOCATEALL;
+ prealloc.fst_posmode = F_PEOFPOSMODE;
+ prealloc.fst_offset = offset;
+ prealloc.fst_length = len;
+
+ return fcntl(fd, F_PREALLOCATE, &prealloc);
+#else
+ return posix_fallocate(fd, offset, len);
+#endif
+}
+
#ifdef NO_MMAP
#include "map.h"
diff --git a/src/posix.h b/src/posix.h
index 2934f2479..0119b6bb7 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -115,6 +115,7 @@ extern int p_open(const char *path, int flags, ...);
extern int p_creat(const char *path, mode_t mode);
extern int p_getcwd(char *buffer_out, size_t size);
extern int p_rename(const char *from, const char *to);
+extern int p_fallocate(int fd, off_t offset, off_t len);
extern int git__page_size(size_t *page_size);
extern int git__mmap_alignment(size_t *page_size);
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index d8bbebb5d..835804de4 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -516,6 +516,12 @@ int p_creat(const char *path, mode_t mode)
return p_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
+int p_fallocate(int fd, off_t offset, off_t len)
+{
+ error = ENOSYS;
+ return -1;
+}
+
int p_utimes(const char *path, const struct p_timeval times[2])
{
git_win32_path wpath;