compat / win32mmap.con commit Merge branch 'js/test-hashmap-squelch-gcc' (6d43519)
   1#include "../git-compat-util.h"
   2
   3void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
   4{
   5        HANDLE hmap;
   6        void *temp;
   7        off_t len;
   8        struct stat st;
   9        uint64_t o = offset;
  10        uint32_t l = o & 0xFFFFFFFF;
  11        uint32_t h = (o >> 32) & 0xFFFFFFFF;
  12
  13        if (!fstat(fd, &st))
  14                len = st.st_size;
  15        else
  16                die("mmap: could not determine filesize");
  17
  18        if ((length + offset) > len)
  19                length = xsize_t(len - offset);
  20
  21        if (!(flags & MAP_PRIVATE))
  22                die("Invalid usage of mmap when built with USE_WIN32_MMAP");
  23
  24        hmap = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL,
  25                PAGE_WRITECOPY, 0, 0, NULL);
  26
  27        if (!hmap)
  28                return MAP_FAILED;
  29
  30        temp = MapViewOfFileEx(hmap, FILE_MAP_COPY, h, l, length, start);
  31
  32        if (!CloseHandle(hmap))
  33                warning("unable to close file mapping handle");
  34
  35        return temp ? temp : MAP_FAILED;
  36}
  37
  38int git_munmap(void *start, size_t length)
  39{
  40        return !UnmapViewOfFile(start);
  41}