I tried to debug it, it seems headerRead expects timedRead(fd, (char *)&ei[2], len) to always read the full requested size but it does not (it often only gets 4992 bytes).
Just to test I changed the code to be
if ((a=timedRead(fd, (char *)&ei[2], len)) != len) {
int p = 0;
while ((a > 0) && (a < len)) {
len -= a;
p += a;
a = timedRead(fd, (char *)&ei[2]+p, len);
}
if (a < len) { goto exit;
}
}
I tried to debug it, it seems headerRead expects timedRead(fd, (char *)&ei[2], len) to always read the full requested size but it does not (it often only gets 4992 bytes).
Just to test I changed the code to be
if ((a=timedRead(fd, (char *)&ei[2], len)) != len) {
goto exit;
int p = 0;
while ((a > 0) && (a < len)) {
len -= a;
p += a;
a = timedRead(fd, (char *)&ei[2]+p, len);
}
if (a < len) {
}
}
And it can now load all the headers.