dj(1): remove Io_bufxfer
This commit is contained in:
parent
3e1735f778
commit
b74160fa4e
32
src/dj.c
32
src/dj.c
@ -75,21 +75,6 @@ Io_bufrpad(struct Io *io, int padding){
|
||||
return io;
|
||||
}
|
||||
|
||||
/* Copies from the buffer in src to the buffer in dest no more than n units,
|
||||
* removing the copied units from src and permuting the remaining units in the
|
||||
* src buffer to the start of the buffer, modifying both the src and dest
|
||||
* bufuse and returning dest. */
|
||||
static struct Io*
|
||||
Io_bufxfer(struct Io *dest, struct Io *src, int n){
|
||||
|
||||
assert(dest != NULL && src != NULL);
|
||||
|
||||
memcpy(dest->buf, src->buf, (dest->bufuse = n));
|
||||
memmove(src->buf, src->buf + n, (src->bufuse -= n));
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* Opens io->fn and saves the file descriptor into io->fd. Returns io->fd,
|
||||
* which will be -1 if an error occured. */
|
||||
static int
|
||||
@ -318,10 +303,18 @@ int main(int argc, char *argv[]){
|
||||
do{
|
||||
int t;
|
||||
|
||||
if(io[1].bs > io[0].bs){
|
||||
if(io[0].bs <= io[1].bs){
|
||||
int n;
|
||||
|
||||
/* copy from ibuf as much as possible to the obuf */
|
||||
/* saturate obuf */
|
||||
memcpy(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) */ {
|
||||
int n;
|
||||
|
||||
/* drain what we can from ibuf */
|
||||
memcpy(io[1].buf + io[1].bufuse, io[0].buf,
|
||||
(n = MIN(io[0].bufuse, io[1].bs - io[1].bufuse)));
|
||||
io[1].bufuse += n;
|
||||
@ -330,9 +323,8 @@ int main(int argc, char *argv[]){
|
||||
io[0].bufuse -= n;
|
||||
|
||||
if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1)
|
||||
continue; /* we could write more */
|
||||
}else
|
||||
Io_bufxfer(&io[1], &io[0], MIN(io[0].bufuse, io[1].bs));
|
||||
continue; /* obuf not saturated - we could write more */
|
||||
}
|
||||
|
||||
t = io[1].bufuse;
|
||||
Io_write(&io[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user