dj(1): replace do/while in write loop
This commit is contained in:
parent
a01cea572d
commit
71f4a411b6
28
src/dj.c
28
src/dj.c
@ -331,21 +331,20 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
/* write */
|
||||
do { /* while(io[0].bufuse > 0); */
|
||||
int t;
|
||||
assert(io[0].bufuse > 0);
|
||||
|
||||
while (io[0].bufuse > 0) { /* write */
|
||||
if (io[0].bs <= io[1].bs) {
|
||||
int n;
|
||||
|
||||
/* saturate obuf */
|
||||
memcpy(
|
||||
memcpy( /* saturate obuf */
|
||||
io[1].buf, io[0].buf,
|
||||
(io[1].bufuse = (n = MIN(io[0].bufuse, io[1].bs)))
|
||||
);
|
||||
|
||||
/* permute the copied units out of ibuf */
|
||||
memmove(io[0].buf, &(io[0].buf)[n], (io[0].bufuse -= n));
|
||||
} else /* if(io[0].bs < io[1].bs) */ {
|
||||
} else /* if(io[0].bs > io[1].bs) */ {
|
||||
int n;
|
||||
|
||||
/* drain what we can from ibuf */
|
||||
@ -353,12 +352,10 @@ int main(int argc, char *argv[]) {
|
||||
&(io[1].buf)[io[1].bufuse], io[0].buf,
|
||||
(n = MIN(io[0].bufuse, io[1].bs - io[1].bufuse))
|
||||
);
|
||||
|
||||
io[1].bufuse += n;
|
||||
|
||||
/* permute out the copied units */
|
||||
memmove(io[0].buf, &(io[0].buf)[n], io[0].bs - n);
|
||||
|
||||
io[0].bufuse -= n;
|
||||
|
||||
if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1) {
|
||||
@ -366,17 +363,28 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
{ /* writes actually happen, or die */
|
||||
size_t t;
|
||||
|
||||
t = io[1].bufuse;
|
||||
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 */
|
||||
}
|
||||
|
||||
assert(io[1].error == 0 || io[1].bufuse == t);
|
||||
/* if the Io_writes errored, bufuse wouldn't have changed, and
|
||||
* the error will be reported at the end of the read/write
|
||||
* loop */
|
||||
|
||||
assert(io[1].bufuse <= t);
|
||||
|
||||
if (io[1].bufuse == t) { /* no more love */
|
||||
count = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < io[1].bufuse /* && io[1].bufuse < t */) {
|
||||
fprintf(stderr, "%s: Partial write:\n\t", program_name);
|
||||
@ -384,7 +392,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if(!noerror) { count = 1; }
|
||||
}
|
||||
} while(io[0].bufuse > 0);
|
||||
}
|
||||
} while(count == 0 || --count > 0);
|
||||
|
||||
fprintio(stderr, fmt, io);
|
||||
|
Loading…
Reference in New Issue
Block a user