]> Devi Nivas Git - cs3210-lab1.git/commitdiff
Check result of write (thans to Alexander Kapshuk <alexander.kapshuk@gmail)
authorFrans Kaashoek <kaashoek@mit.edu>
Mon, 19 Sep 2016 11:01:30 +0000 (07:01 -0400)
committerFrans Kaashoek <kaashoek@mit.edu>
Mon, 19 Sep 2016 11:01:30 +0000 (07:01 -0400)
cat.c

diff --git a/cat.c b/cat.c
index 2b2dcc7a5642d72c5bd358636940ca1d4fdd20a6..5ddc820d69c3d7fd7632a50fc1b6e84c0aa4a168 100644 (file)
--- 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();