MCPcopy Create free account
hub / github.com/ConfettiFX/The-Forge / ioWindowsFsMemoryMap

Function ioWindowsFsMemoryMap

Common_3/OS/Windows/WindowsFileSystem.cpp:261–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259}
260
261static bool ioWindowsFsMemoryMap(FileStream* fs, size_t* outSize, void const** outData)
262{
263 __FS_NO_ERR;
264 *outSize = 0;
265 *outData = NULL;
266
267 if (fs->mMode & FM_WRITE)
268 {
269 // Cannot memory map on files with WRITE access
270 __FS_SET_ERR(FS_NOT_PERMITTED_ERR);
271 return false;
272 }
273
274 WSD(stream, fs);
275
276 // mapped already
277 if (!stream->mapView)
278 {
279 HANDLE fileMapping = CreateFileMappingW(stream->handle, NULL, PAGE_READONLY, 0, 0, NULL);
280 if (!fileMapping)
281 {
282 __FS_SET_ERR(FS_INTERNAL_ERR);
283 return false;
284 }
285
286 ASSERT(GetLastError() != ERROR_ALREADY_EXISTS);
287
288 LPVOID mem = MapViewOfFile(fileMapping, FILE_MAP_READ, 0, 0, 0);
289 if (!mem)
290 {
291 __FS_SET_ERR(FS_INTERNAL_ERR);
292 CloseHandle(fileMapping);
293 return false;
294 }
295
296 stream->fileMapping = fileMapping;
297 stream->mapView = mem;
298 }
299
300 *outSize = ioWindowsFsGetSize(fs);
301 *outData = stream->mapView;
302 return true;
303}
304
305static bool ioWindowsFsClose(FileStream* fs)
306{

Callers

nothing calls this directly

Calls 1

ioWindowsFsGetSizeFunction · 0.85

Tested by

no test coverage detected