bore

Unnamed repository
Log | Files | Refs

commit 46afedf20555edcb8551eff4ab2159eb38585edb
parent a1ba22ff44110d3ccb93d6f5a0313abc370d55e7
Author: aabacchus <ben@bvnf.space>
Date:   Thu, 16 Sep 2021 03:39:03 +0100

cat: if read fails actually check it

-1 is not > 0

Diffstat:
Mcat.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cat.c b/cat.c @@ -11,15 +11,15 @@ cat(int fd, char *fname) { unsigned char buf[BUF_SIZE]; ssize_t n; while ((n = read(fd, buf, BUF_SIZE)) > 0) { - if (n == -1){ - fprintf(stderr, "cat: read %s: %s\n", fname, strerror(errno)); - return 1; - } if (write(1, buf, n) == -1) { fprintf(stderr, "cat: write: %s\n", strerror(errno)); return 1; } } + if (n == -1){ + fprintf(stderr, "cat: read %s: %s\n", fname, strerror(errno)); + return 1; + } return 0; }