MCPcopy Create free account
hub / github.com/MemNixFS/MemNixFS / read

Method read

src/io/file_memory_source.cpp:37–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 const std::string& name() const override { return name_; }
36
37 std::size_t read(u64 offset, void* out, std::size_t len) const override {
38 if (offset >= size_) return 0;
39 // Overflow-safe clamp (offset < size_ guaranteed above, so the
40 // subtraction can't underflow); `offset + len` could wrap for huge len.
41 if (len > size_ - offset) len = static_cast<std::size_t>(size_ - offset);
42 std::lock_guard<std::mutex> lk(mu_);
43 if (LMPFS_FSEEK64(fp_, static_cast<i64>(offset), SEEK_SET) != 0)
44 throw_error("seek({}) failed in {}", offset, name_);
45 std::size_t got = std::fread(out, 1, len, fp_);
46 if (got != len && std::ferror(fp_))
47 throw_error("read({},{}) failed in {}", offset, len, name_);
48 return got;
49 }
50
51private:
52 std::FILE* fp_ = nullptr;

Callers

nothing calls this directly

Calls 1

throw_errorFunction · 0.85

Tested by

no test coverage detected