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

Method readToString

KittyMemoryEx/KittyIOFile.cpp:134–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134bool KittyIOFile::readToString(std::string *str)
135{
136 _error = 0;
137
138 if (!str)
139 return false;
140
141 str->clear();
142
143 auto s = info();
144 if (_error == 0 && s.st_size > 0)
145 {
146 str->resize(s.st_size);
147 return (size_t)pread(0, str->data(), s.st_size) == (size_t)s.st_size;
148 }
149
150 std::vector<char> buffer(_bufferSize);
151 uintptr_t offset = 0;
152 while (true)
153 {
154 ssize_t n = pread(offset, buffer.data(), buffer.size());
155 if (n <= 0)
156 break;
157
158 offset += n;
159 str->append(buffer.data(), n);
160 }
161
162 return _error == 0;
163}
164
165bool KittyIOFile::readToBuffer(std::vector<char> *buf)
166{

Callers 1

readFileToStringMethod · 0.80

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected