dj(1): (broken) move hard skipping to the main loop

This commit is contained in:
dtb 2024-07-04 20:27:31 -06:00
parent 9f420131ee
commit 906eb92f5a
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -72,7 +72,8 @@ Io_read(struct Io *io){
assert(io->bs > 0); assert(io->bs > 0);
io->bytes += (io->bufuse = read(io->fd, io->buf, io->bs)); io->bytes += (io->bufuse = read(io->fd, &(io->buf)[io->bufuse],
io->bs - io->bufuse));
assert(io->bufuse <= io->bs); assert(io->bufuse <= io->bs);
@ -233,19 +234,6 @@ int main(int argc, char *argv[]){
io[i].seek = 0; io[i].seek = 0;
} }
/* hard skipping */
if(io[0].seek > 0){
do{
if((io[0].bufuse = read(
io[0].fd, io[0].buf, MIN(io[0].bs, io[0].seek)))
== 0)
/* second chance */
io->bufuse = read(
io[0].fd, io[0].buf, MIN(io[0].bs, io[0].seek));
}while((io[0].seek -= io[0].bufuse) > 0 && io[0].bufuse != 0);
io[0].bufuse = 0;
}
/* hard seeking */ /* hard seeking */
if(io[1].seek > 0){ if(io[1].seek > 0){
memset(io[1].buf, '\0', io[1].bs); memset(io[1].buf, '\0', io[1].bs);
@ -265,9 +253,8 @@ int main(int argc, char *argv[]){
/* Sought bytes aren't counted in the statistics because successful seeking /* Sought bytes aren't counted in the statistics because successful seeking
* is guaranteed here. */ * is guaranteed here. */
for(i = 0; i < 2; ++i) if(io[1].seek > 0)
if(io[i].seek > 0) return oserr(io[1].fn);
return oserr(io[i].fn);
do{ do{
assert(io[0].bufuse == 0); assert(io[0].bufuse == 0);
@ -279,6 +266,9 @@ int main(int argc, char *argv[]){
if(io[0].seek > 0) if(io[0].seek > 0)
skipping = 1; skipping = 1;
if(skipping && io[0].seek < io[0].bs)
io[0].bufuse = io[0].bs - io[0].seek;
t = io[0].bufuse; t = io[0].bufuse;
if(Io_read(&io[0])->bufuse == t && !noerror) if(Io_read(&io[0])->bufuse == t && !noerror)
Io_read(&io[0]); /* second chance */ Io_read(&io[0]); /* second chance */
@ -297,6 +287,13 @@ int main(int argc, char *argv[]){
io->bufuse = io->bs; io->bufuse = io->bs;
} }
} }
if(skipping){
skipping = (io[0].seek -= io[0].bufuse - t) > 0;
io[0].bufuse = 0;
count += (count != 0);
continue;
}
} }
/* write */ /* write */