Windows implementation of pread. Note that this DOES move the file descriptors read position, but it does so atomically.
| 157 | // Windows implementation of pread. Note that this DOES move the file descriptors read position, |
| 158 | // but it does so atomically. |
| 159 | static ssize_t pread(int fd, void* data, size_t byte_count, off64_t offset) { |
| 160 | DWORD bytes_read; |
| 161 | OVERLAPPED overlapped; |
| 162 | memset(&overlapped, 0, sizeof(OVERLAPPED)); |
| 163 | overlapped.Offset = static_cast<DWORD>(offset); |
| 164 | overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32); |
| 165 | if (!ReadFile(reinterpret_cast<HANDLE>(_get_osfhandle(fd)), data, static_cast<DWORD>(byte_count), |
| 166 | &bytes_read, &overlapped)) { |
| 167 | // In case someone tries to read errno (since this is masquerading as a POSIX call) |
| 168 | errno = EIO; |
| 169 | return -1; |
| 170 | } |
| 171 | return static_cast<ssize_t>(bytes_read); |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | bool ReadFullyAtOffset(int fd, void* data, size_t byte_count, off64_t offset) { |
no outgoing calls
no test coverage detected