//////////////////////////////////////////////////////////////////////// MappedFile ////////////////////////////////////////////////////////////////////////
| 110 | // MappedFile |
| 111 | ///////////////////////////////////////////////////////////////////////////// |
| 112 | void MappedFile::Open(std::string const & fName) |
| 113 | { |
| 114 | Close(); |
| 115 | |
| 116 | #ifdef OMIM_OS_WINDOWS |
| 117 | m_hFile = CreateFileA(fName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
| 118 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); |
| 119 | if (m_hFile == INVALID_HANDLE_VALUE) |
| 120 | MYTHROW(Reader::OpenException, ("Can't open file:", fName, "win last error:", GetLastError())); |
| 121 | m_hMapping = CreateFileMappingA(m_hFile, NULL, PAGE_READONLY, 0, 0, NULL); |
| 122 | if (m_hMapping == NULL) |
| 123 | MYTHROW(Reader::OpenException, ("Can't create file's Windows mapping:", fName, "win last error:", GetLastError())); |
| 124 | #else |
| 125 | m_fd = open(fName.c_str(), O_RDONLY | O_NONBLOCK); |
| 126 | if (m_fd == -1) |
| 127 | { |
| 128 | if (errno == EMFILE || errno == ENFILE) |
| 129 | MYTHROW(Reader::TooManyFilesException, ("Can't open file:", fName, ", reason:", strerror(errno))); |
| 130 | else |
| 131 | MYTHROW(Reader::OpenException, ("Can't open file:", fName, ", reason:", strerror(errno))); |
| 132 | } |
| 133 | #endif |
| 134 | } |
| 135 | |
| 136 | void MappedFile::Close() |
| 137 | { |