MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / pread

Method pread

KittyMemoryEx/KittyIOFile.cpp:80–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 return total > 0 ? total : (_error == 0 ? 0 : -1);
79 }
80 total += n;
81 }
82 return total;
83}
84
85ssize_t KittyIOFile::pread(kt_off64_t offset, void *buffer, size_t len)
86{
87 _error = 0;
88
89 if (_fd < 0)
90 return -1;
91
92 char *ptr = static_cast<char *>(buffer);
93 size_t total = 0;
94
95 while (total < len)
96 {
97 size_t toRead = std::min(len - total, KT_IO_CHUNK_SIZE);
98 ssize_t n = KT_EINTR_RETRY(kt_pread64(_fd, ptr + total, toRead, (kt_off64_t)(offset + total)));
99 if (n <= 0)
100 {
101 _error = (n < 0) ? errno : 0;
102 return total > 0 ? total : (_error == 0 ? 0 : -1);
103 }
104 total += n;
105 }
106 return total;
107}
108

Callers 1

ReadMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected