MCPcopy Create free account
hub / github.com/apache/arrow / pread_compat

Function pread_compat

cpp/src/arrow/util/io_util.cc:1622–1646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1620//
1621
1622static inline int64_t pread_compat(int fd, void* buf, int64_t nbytes, int64_t pos) {
1623#if defined(_WIN32)
1624 HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
1625 DWORD dwBytesRead = 0;
1626 OVERLAPPED overlapped = {};
1627 overlapped.Offset = static_cast<uint32_t>(pos);
1628 overlapped.OffsetHigh = static_cast<uint32_t>(pos >> 32);
1629
1630 // Note: ReadFile() will update the file position
1631 BOOL bRet =
1632 ReadFile(handle, buf, static_cast<uint32_t>(nbytes), &dwBytesRead, &overlapped);
1633 if (bRet || GetLastError() == ERROR_HANDLE_EOF) {
1634 return dwBytesRead;
1635 } else {
1636 return -1;
1637 }
1638#else
1639 int64_t ret;
1640 do {
1641 ret = static_cast<int64_t>(
1642 pread(fd, buf, static_cast<size_t>(nbytes), static_cast<off_t>(pos)));
1643 } while (ret == -1 && errno == EINTR);
1644 return ret;
1645#endif
1646}
1647
1648Result<int64_t> FileRead(int fd, uint8_t* buffer, int64_t nbytes) {
1649#if defined(_WIN32)

Callers 1

FileReadAtFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected