Skip to content
Draft
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
17 changes: 14 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,20 @@ void *run_sort(void *v) {
std::string s;
s.resize(end - start);

if (pread(a->indexfd, (void *) s.c_str(), end - start, start) != end - start) {
fprintf(stderr, "pread(index): %s\n", strerror(errno));
exit(EXIT_READ);
const char *dest = s.c_str();
ssize_t off = start;
ssize_t count = end - start;

while (count > 0) {
ssize_t n = pread(a->indexfd, (void *) dest, count, off);
if (n < 0) {
fprintf(stderr, "pread(index): %s\n", strerror(errno));
exit(EXIT_READ);
}

dest += n;
off += n;
count -= n;
}

qsort((void *) s.c_str(), (end - start) / a->bytes, a->bytes, indexcmp);
Expand Down