/ * 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. */
| 312 | * and map a view of the entire file. Returns True on success, and fills in f. |
| 313 | */ |
| 314 | Bool 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. |
no outgoing calls
no test coverage detected