dj(1): replace do/while on hard seeking
This commit is contained in:
parent
f7ebe7cf57
commit
a01cea572d
33
src/dj.c
33
src/dj.c
@ -259,28 +259,27 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hard seeking */
|
assert(io[1].bufuse == 0); /* requirement for hard seeking */
|
||||||
if (io[1].seek > 0) {
|
|
||||||
size_t t;
|
|
||||||
|
|
||||||
do {
|
/* hard seeking; t is io[1].bufuse, before Io_write subtracts from it */
|
||||||
memset(
|
for(size_t t; io[1].seek > 0; io[1].seek -= (t - io[1].bufuse)) {
|
||||||
io[1].buf, '\0',
|
memset(
|
||||||
(t = io[1].bufuse = MIN(io[1].bs, io[1].seek))
|
io[1].buf, '\0', /* set buf to all nulls */
|
||||||
);
|
(t = io[1].bufuse = MIN(io[1].bs, io[1].seek)) /* saturate block */
|
||||||
|
);
|
||||||
|
|
||||||
if (Io_write(&io[1])->bufuse == t && !noerror && io[1].error == 0) {
|
if (Io_write(&io[1])->bufuse == t && !noerror && io[1].error == 0) {
|
||||||
Io_write(&io[1]); /* second chance */
|
Io_write(&io[1]); /* second chance */
|
||||||
}
|
}
|
||||||
if (io[1].error != 0) {
|
|
||||||
return oserr(io[1].fn, io[1].error);
|
|
||||||
}
|
|
||||||
} while ((io[1].seek -= (t - io[1].bufuse)) > 0 && io[1].bufuse != t);
|
|
||||||
|
|
||||||
io[1].bufuse = 0;
|
if (io[1].error != 0) { return oserr(io[1].fn, io[1].error); }
|
||||||
|
|
||||||
|
if (io[1].bufuse == t) { break; } /* all writes failed! */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (io[1].seek > 0) {
|
io[1].bufuse = 0;
|
||||||
|
|
||||||
|
if (io[1].seek > 0) { /* hard seeking failed */
|
||||||
fprintio(stderr, fmt, io);
|
fprintio(stderr, fmt, io);
|
||||||
return oserr(io[1].fn, errno);
|
return oserr(io[1].fn, errno);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user