MCPcopy Create free account
hub / github.com/Meridian59/Meridian59 / MappedFileOpenRead

Function MappedFileOpenRead

roomedit/source/dibutil.cpp:314–342  ·  view source on GitHub ↗

/ * MappedFileOpenRead: Open filename as a memory-mapped file for read-only access, * and map a view of the entire file. Returns True on success, and fills in f. */

Source from the content-addressed store, hash-verified

312 * and map a view of the entire file. Returns True on success, and fills in f.
313 */
314Bool MappedFileOpenRead(const char *filename, file_node *f)
315{
316 f->fh = CreateFile(filename,GENERIC_READ,0,NULL,
317 OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
318 if (f->fh == INVALID_HANDLE_VALUE)
319 {
320 return False;
321 }
322
323 f->length = GetFileSize(f->fh, NULL);
324
325 f->mapfh = CreateFileMapping(f->fh,NULL,PAGE_READONLY,0,f->length,NULL);
326 if (f->mapfh == NULL)
327 {
328 CloseHandle(f->fh);
329 return False;
330 }
331
332 f->mem = (char *) MapViewOfFile(f->mapfh,FILE_MAP_READ,0,0,0);
333 if (f->mem == NULL)
334 {
335 CloseHandle(f->mapfh);
336 CloseHandle(f->fh);
337 return False;
338 }
339
340 f->ptr = f->mem;
341 return True;
342}
343/***************************************************************************/
344/*
345 * MappedFileRead: Copy num bytes from the memory-mapped file to buf.

Callers 2

DibOpenFileFunction · 0.70
DibOpenFileSimpleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected