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

Method writeToFd

KittyMemoryEx/KittyIOFile.cpp:225–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225bool KittyIOFile::writeToFd(int fd)
226{
227 _error = 0;
228
229 if (_fd < 0 || fd < 0)
230 return false;
231
232 std::vector<char> buffer(_bufferSize);
233 uintptr_t offset = 0;
234
235 while (true)
236 {
237 ssize_t nr = pread(offset, buffer.data(), buffer.size());
238 if (nr < 0)
239 return false;
240
241 if (nr == 0)
242 break;
243
244 ssize_t total_nw = 0;
245 while (total_nw < nr)
246 {
247 ssize_t nw = KT_EINTR_RETRY(::write(fd, buffer.data() + total_nw, nr - total_nw));
248 if (nw <= 0)
249 {
250 _error = (nw < 0) ? errno : 0;
251 return false;
252 }
253 total_nw += nw;
254 }
255
256 offset += nr;
257 }
258
259 return true;
260}
261
262void KittyIOFile::listFilesCallback(const std::string &dirPath, std::function<bool(const std::string &)> cb)
263{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected