| 31 | } |
| 32 | |
| 33 | void AutoFile::seek(int64_t offset, int origin) |
| 34 | { |
| 35 | if (IsNull()) { |
| 36 | throw std::ios_base::failure("AutoFile::seek: file handle is nullptr"); |
| 37 | } |
| 38 | if (std::fseek(m_file, offset, origin) != 0) { |
| 39 | throw std::ios_base::failure(feof() ? "AutoFile::seek: end of file" : "AutoFile::seek: fseek failed"); |
| 40 | } |
| 41 | if (origin == SEEK_SET) { |
| 42 | m_position = offset; |
| 43 | } else if (origin == SEEK_CUR && m_position.has_value()) { |
| 44 | *m_position += offset; |
| 45 | } else { |
| 46 | int64_t r{std::ftell(m_file)}; |
| 47 | if (r < 0) { |
| 48 | throw std::ios_base::failure("AutoFile::seek: ftell failed"); |
| 49 | } |
| 50 | m_position = r; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | int64_t AutoFile::tell() |
| 55 | { |