| 783 | // MappedFile implementation |
| 784 | |
| 785 | MappedFile::MappedFile(const std::string& filename) |
| 786 | : fd_(-1), mapped_data_(nullptr), file_size_(0), data_offset_(0) { |
| 787 | fd_ = open(filename.c_str(), O_RDONLY); |
| 788 | if (fd_ == -1) { |
| 789 | throw std::runtime_error("Cannot open file for mapping: " + filename); |
| 790 | } |
| 791 | |
| 792 | struct stat st; |
| 793 | if (fstat(fd_, &st) == -1) { |
| 794 | close(fd_); |
| 795 | throw std::runtime_error("Cannot get file size: " + filename); |
| 796 | } |
| 797 | file_size_ = static_cast<size_t>(st.st_size); |
| 798 | |
| 799 | mapped_data_ = mmap(nullptr, file_size_, PROT_READ, MAP_SHARED, fd_, 0); |
| 800 | if (mapped_data_ == MAP_FAILED) { |
| 801 | close(fd_); |
| 802 | throw std::runtime_error("Cannot map file: " + filename); |
| 803 | } |
| 804 | |
| 805 | close(fd_); |
| 806 | fd_ = -1; |
| 807 | |
| 808 | parse_header(); |
| 809 | apply_madvise_hints(); |
| 810 | } |
| 811 | |
| 812 | MappedFile::~MappedFile() { |
| 813 | if (mapped_data_ != nullptr && mapped_data_ != MAP_FAILED) { |
nothing calls this directly
no outgoing calls
no test coverage detected