MCPcopy Create free account
hub / github.com/AGWA/git-crypt / xsgetn

Method xsgetn

fhstream.cpp:173–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173std::streamsize ifhbuf::xsgetn (char* s, std::streamsize n)
174{
175 // Use heuristic to decide whether to read directly
176 // Read directly only if n >= bytes_available + 4096
177
178 std::streamsize bytes_available = egptr() - gptr();
179
180 if (n < bytes_available + 4096) {
181 // Not worth it to do a direct read
182 return std::streambuf::xsgetn(s, n);
183 }
184
185 std::streamsize total_bytes_read = 0;
186
187 // First, copy out the bytes currently in the buffer
188 std::memcpy(s, gptr(), bytes_available);
189
190 s += bytes_available;
191 n -= bytes_available;
192 total_bytes_read += bytes_available;
193
194 // Now do the direct read
195 while (n > 0) {
196 const size_t bytes_read = read_fun(handle, s, n);
197 if (bytes_read == 0) {
198 // EOF
199 break;
200 }
201
202 s += bytes_read;
203 n -= bytes_read;
204 total_bytes_read += bytes_read;
205 }
206
207 // Fill up the putback area with the most recently read characters
208 size_t nputback = std::min<size_t>(total_bytes_read, putback_size);
209 std::memcpy(buffer + (putback_size - nputback), s - nputback, nputback);
210
211 // Reset the buffer with no bytes available for reading, but with some putback characters
212 reset_buffer(nputback, 0);
213
214 // Return the total number of bytes read
215 return total_bytes_read;
216}
217
218std::streambuf* ifhbuf::setbuf (char* s, std::streamsize n)
219{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected