| 188 | } |
| 189 | |
| 190 | int FileIo::munmap() { |
| 191 | int rc = 0; |
| 192 | if (p_->pMappedArea_) { |
| 193 | #if defined _WIN32 |
| 194 | UnmapViewOfFile(p_->pMappedArea_); |
| 195 | CloseHandle(p_->hMap_); |
| 196 | p_->hMap_ = nullptr; |
| 197 | CloseHandle(p_->hFile_); |
| 198 | p_->hFile_ = nullptr; |
| 199 | #elif __has_include(<sys/mman.h>) |
| 200 | if (::munmap(p_->pMappedArea_, p_->mappedLength_) != 0) { |
| 201 | rc = 1; |
| 202 | } |
| 203 | #else |
| 204 | #error Platforms without mmap are not supported. See https://github.com/Exiv2/exiv2/issues/2380 |
| 205 | if (p_->isWriteable_) { |
| 206 | seek(0, BasicIo::beg); |
| 207 | write(p_->pMappedArea_, p_->mappedLength_); |
| 208 | } |
| 209 | if (p_->isMalloced_) { |
| 210 | delete[] p_->pMappedArea_; |
| 211 | p_->isMalloced_ = false; |
| 212 | } |
| 213 | #endif |
| 214 | } |
| 215 | if (p_->isWriteable_) { |
| 216 | if (p_->fp_) |
| 217 | p_->switchMode(Impl::opRead); |
| 218 | p_->isWriteable_ = false; |
| 219 | } |
| 220 | p_->pMappedArea_ = nullptr; |
| 221 | p_->mappedLength_ = 0; |
| 222 | return rc; |
| 223 | } |
| 224 | |
| 225 | byte* FileIo::mmap(bool isWriteable) { |
| 226 | if (munmap() != 0) { |
nothing calls this directly
no test coverage detected