4 static inline size_t xsize_t(off_t len
)
6 if (len
> (size_t) len
)
7 die("Cannot handle files this big");
11 void *win32_mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
18 uint32_t l
= o
& 0xFFFFFFFF;
19 uint32_t h
= (o
>> 32) & 0xFFFFFFFF;
24 printf("mmap: could not determine filesize");
26 if ((length
+ offset
) > len
)
27 length
= xsize_t(len
- offset
);
29 if (!(flags
& MAP_PRIVATE
))
30 printf("Invalid usage of mmap when built with USE_WIN32_MMAP");
32 hmap
= CreateFileMapping((HANDLE
)_get_osfhandle(fd
), 0, PAGE_WRITECOPY
,
38 temp
= MapViewOfFileEx(hmap
, FILE_MAP_COPY
, h
, l
, length
, start
);
40 if (!CloseHandle(hmap
))
41 printf("unable to close file mapping handle");
43 return temp
? temp
: MAP_FAILED
;
46 int win32_munmap(void *start
, size_t length
)
48 return !UnmapViewOfFile(start
);