Set path to file manager. See "include/loader/filemgr.h".
| 12 | |
| 13 | // Set path to file manager. See "include/loader/filemgr.h". |
| 14 | Expect<void> FileMgr::setPath(const std::filesystem::path &FilePath) { |
| 15 | reset(); |
| 16 | std::error_code ErrCode; |
| 17 | Size = std::filesystem::file_size(FilePath, ErrCode); |
| 18 | if (likely(!ErrCode)) { |
| 19 | if (!MMap::supported()) { |
| 20 | Size = 0; |
| 21 | Status = ErrCode::Value::IllegalPath; |
| 22 | return Unexpect(Status); |
| 23 | } |
| 24 | FileMap.emplace(FilePath); |
| 25 | if (auto *Pointer = FileMap->address(); likely(Pointer)) { |
| 26 | Data = reinterpret_cast<const Byte *>(Pointer); |
| 27 | Status = ErrCode::Value::Success; |
| 28 | } else { |
| 29 | // File size is 0, mmap failed. |
| 30 | // Will get 'UnexpectedEnd' error while the first reading. |
| 31 | FileMap.reset(); |
| 32 | } |
| 33 | return {}; |
| 34 | } |
| 35 | Size = 0; |
| 36 | Status = ErrCode::Value::IllegalPath; |
| 37 | return Unexpect(Status); |
| 38 | } |
| 39 | |
| 40 | // Set code data. See "include/loader/filemgr.h". |
| 41 | Expect<void> FileMgr::setCode(Span<const Byte> CodeData) { |