Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lab/vtpc/test/lib/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ struct io {
std::function<int(int fd)> fsync;
};

template <class A>
void robust_do(A action, int fd, auto buf, size_t count) {
template <class A, class T>
void robust_do(A action, int fd, T* buf, size_t count) {
using B = std::conditional_t<
std::is_const_v<std::remove_pointer_t<T>>,
const char,
char>;

size_t total = 0;
while (total < count) {
const ssize_t local = action(fd, buf, count);
const size_t tail_count = count - total;
B* tail_buf = reinterpret_cast<B*>(buf) + total; // NOLINT
const ssize_t local = action(fd, tail_buf, tail_count);
if (local < 0) {
throw vt::file_exception(local)
<< "failed to read/write " << count << " bytes from file with fd "
Expand Down