summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2009-01-03 00:36:10 -0800
committerShawn O. Pearce <spearce@spearce.org>2009-01-03 01:16:02 -0800
commit20e7f426c3d56ba9e4b55f31a61835dd0031b464 (patch)
treeeb7100b307f2c35e7a2d1b05125cb58702da2897 /src/fileops.c
parent098ac57a13165290bad223e4949fc6f13960b604 (diff)
downloadlibgit2-20e7f426c3d56ba9e4b55f31a61835dd0031b464.tar.gz
Add a simple mmap wrapper for cross-platform mmap usage
Win32 has a variant of mmap that is harder to use than POSIX, but to run natively and efficiently on Win32 we need some form of it. gitfo_map_ro() provides a basic mmap function for use in locations where we need read-only random data access to large ranges of a file, such as a pack-*.idx. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 16b9dc520..f494e4772 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -1,5 +1,6 @@
#include "common.h"
#include "fileops.h"
+#include <sys/mman.h>
int gitfo_open(const char *path, int flags)
{
@@ -106,6 +107,20 @@ void gitfo_free_buf(gitfo_buf *obj)
obj->data = NULL;
}
+int gitfo_map_ro(gitfo_map *out, git_file fd, off_t begin, size_t len)
+{
+ out->data = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, begin);
+ if (out->data == (void*)-1)
+ return git_os_error();
+ out->len = len;
+ return GIT_SUCCESS;
+}
+
+void gitfo_free_map(gitfo_map *out)
+{
+ munmap(out->data, out->len);
+}
+
/* cached diskio */
struct gitfo_cache {
git_file fd;