| 584 | } |
| 585 | |
| 586 | MapContext unmapFile(MapContext ctx) |
| 587 | { |
| 588 | if (!ctx.m_addr) |
| 589 | { |
| 590 | ctx.m_error = "File not mapped."; |
| 591 | return ctx; |
| 592 | } |
| 593 | #ifndef _WIN32 |
| 594 | if (::munmap(ctx.m_addr, ctx.m_size) == -1) |
| 595 | ctx.m_error = "Couldn't unmap file."; |
| 596 | else |
| 597 | { |
| 598 | ctx.m_addr = nullptr; |
| 599 | ctx.m_size = 0; |
| 600 | ctx.m_error = ""; |
| 601 | } |
| 602 | ::close(ctx.m_fd); |
| 603 | #else |
| 604 | if (UnmapViewOfFile(ctx.m_addr) == 0) |
| 605 | ctx.m_error = "Couldn't unmap file."; |
| 606 | else |
| 607 | { |
| 608 | ctx.m_addr = nullptr; |
| 609 | ctx.m_size = 0; |
| 610 | ctx.m_error = ""; |
| 611 | } |
| 612 | CloseHandle(ctx.m_handle); |
| 613 | ::_close(ctx.m_fd); |
| 614 | #endif |
| 615 | return ctx; |
| 616 | } |
| 617 | |
| 618 | } // namespace FileUtils |
| 619 | } // namespace pdal |