From abfe7046e77a3103f01f9b1f7ae9dddf082062ef Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 5 Jul 2024 08:02:09 -0600 Subject: [PATCH] dj(1): fix some type issues --- src/dj.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/dj.c b/src/dj.c index 08df495..2be2ecb 100644 --- a/src/dj.c +++ b/src/dj.c @@ -73,15 +73,16 @@ Io_read(struct Io *io){ assert(io->bs > 0); assert(io->bufuse < io->bs); - io->bufuse += (t = read(io->fd, &(io->buf)[io->bufuse], - io->bs - io->bufuse)); + if((t = read(io->fd, &(io->buf)[io->bufuse], io->bs - io->bufuse)) < 0) + t = 0; + + io->bufuse += t; + io->bytes += t; + io->prec += (0 < io->bufuse && io->bufuse < io->bs); + io->rec += (io->bufuse == io->bs); assert(io->bufuse <= io->bs); - io->bytes += t; - io->prec += (0 < io->bufuse && io->bufuse < io->bs); - io->rec += (io->bufuse == io->bs); - return io; } @@ -96,8 +97,8 @@ Io_write(struct Io *io){ memmove(io->buf, &(io->buf)[t], (io->bufuse -= t)); io->bytes += t; - io->prec += (0 < io->bufuse && 0 < t); - io->rec += (io->bufuse == 0 && 0 < t); + io->prec += (t > 0 && io->bufuse > 0); + io->rec += (t > 0 && io->bufuse == 0); return io; } @@ -258,8 +259,9 @@ int main(int argc, char *argv[]){ { /* read */ char skipping; - int t; + size_t t; + /* hack to intentionally get a partial read from Io_read */ if((skipping = (io[0].seek > 0)) && io[0].seek < io[0].bs) io[0].bufuse = io[0].bs - io[0].seek; @@ -270,8 +272,6 @@ int main(int argc, char *argv[]){ break; if(/* t < io[0].bufuse && */ io[0].bufuse < io[0].bs){ - assert(!skipping); - fprintf(stderr, "%s: Partial read:\n\t", program_name); fprintio(stderr, fmt, io); if(!noerror)