diff --git a/cat.c b/cat.c index 2b2dcc7..5ddc820 100644 --- a/cat.c +++ b/cat.c @@ -9,8 +9,12 @@ cat(int fd) { int n; - while((n = read(fd, buf, sizeof(buf))) > 0) - write(1, buf, n); + while((n = read(fd, buf, sizeof(buf))) > 0) { + if (write(1, buf, n) != n) { + printf(1, "cat: write error\n"); + exit(); + } + } if(n < 0){ printf(1, "cat: read error\n"); exit();