Skip to content

Commit

Permalink
Check result of write (thans to Alexander Kapshuk <alexander.kapshuk@…
Browse files Browse the repository at this point in the history
…gmail)
  • Loading branch information
kaashoek committed Sep 19, 2016
1 parent 912575a commit 89826f4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 89826f4

Please sign in to comment.