1 #include "../git-compat-util.h"
3 void *git_mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
5 HANDLE osfhandle
, hmap
;
9 uint32_t l
= o
& 0xFFFFFFFF;
10 uint32_t h
= (o
>> 32) & 0xFFFFFFFF;
12 osfhandle
= (HANDLE
)_get_osfhandle(fd
);
13 if (!GetFileSizeEx(osfhandle
, &len
))
14 die("mmap: could not determine filesize");
16 if ((length
+ offset
) > len
.QuadPart
)
17 length
= xsize_t(len
.QuadPart
- offset
);
19 if (!(flags
& MAP_PRIVATE
))
20 die("Invalid usage of mmap when built with USE_WIN32_MMAP");
22 hmap
= CreateFileMapping(osfhandle
, NULL
,
23 prot
== PROT_READ
? PAGE_READONLY
: PAGE_WRITECOPY
, 0, 0, NULL
);
30 temp
= MapViewOfFileEx(hmap
, prot
== PROT_READ
?
31 FILE_MAP_READ
: FILE_MAP_COPY
, h
, l
, length
, start
);
33 if (!CloseHandle(hmap
))
34 warning("unable to close file mapping handle");
39 errno
= GetLastError() == ERROR_COMMITMENT_LIMIT
? EFBIG
: EINVAL
;
43 int git_munmap(void *start
, size_t length
)
45 return !UnmapViewOfFile(start
);