dj(1): move prec and rec adjustment into Io_read
This commit is contained in:
parent
4004a4a006
commit
f49a2d2eb8
22
src/dj.c
22
src/dj.c
@ -65,13 +65,24 @@ static int write_flags = O_WRONLY | O_CREAT;
|
||||
#define fdisstd(fd) ((fd) == STDIN_FILENO || (fd) == STDOUT_FILENO)
|
||||
|
||||
/* Reads io->bs bytes from *io's file descriptor into io->buf, storing the
|
||||
* number of read bytes in io->bufuse and updating io->bytes. If io->bufuse is
|
||||
* 0, errno will probably be set. Returns io. */
|
||||
* number of read bytes in io->bufuse and updating io->bytes. If the buf isn't
|
||||
* saturated but is still read into, io->prec will be incremented. If the buf
|
||||
* is saturated, io->rec will be incremented. If io->bufuse is 0, errno will
|
||||
* probably be set. Returns io. */
|
||||
static struct Io *
|
||||
Io_read(struct Io *io){
|
||||
|
||||
io->bytes += (io->bufuse = read(io->fd, io->buf, io->bs));
|
||||
|
||||
assert(io->bufuse <= io->bs);
|
||||
|
||||
if(io->bufuse != 0){
|
||||
if(io->bufuse < io->bs)
|
||||
++io->prec;
|
||||
else /* if(io->bufuse == io->bs) */
|
||||
++io->rec;
|
||||
}
|
||||
|
||||
return io;
|
||||
}
|
||||
|
||||
@ -267,8 +278,8 @@ int main(int argc, char *argv[]){
|
||||
Io_read(&io[0]); /* second chance */
|
||||
if(io[0].bufuse == 0) /* that's all she wrote */
|
||||
break;
|
||||
else if(io[0].bufuse < io[0].bs){
|
||||
++io[0].prec;
|
||||
|
||||
if(io[0].bufuse < io[0].bs){
|
||||
fprintf(stderr, "%s: Partial read:\n\t", program_name);
|
||||
printio(fmt, io);
|
||||
if(!noerror)
|
||||
@ -279,8 +290,7 @@ int main(int argc, char *argv[]){
|
||||
io[0].bs - io[0].bufuse);
|
||||
io->bufuse = io->bs;
|
||||
}
|
||||
}else
|
||||
++io[0].rec;
|
||||
}
|
||||
|
||||
/* write */
|
||||
do{
|
||||
|
Loading…
Reference in New Issue
Block a user