Skip to content

Commit 89826f4

Browse files
committedSep 19, 2016
Check result of write (thans to Alexander Kapshuk <alexander.kapshuk@gmail)
1 parent 912575a commit 89826f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎cat.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ cat(int fd)
99
{
1010
int n;
1111

12-
while((n = read(fd, buf, sizeof(buf))) > 0)
13-
write(1, buf, n);
12+
while((n = read(fd, buf, sizeof(buf))) > 0) {
13+
if (write(1, buf, n) != n) {
14+
printf(1, "cat: write error\n");
15+
exit();
16+
}
17+
}
1418
if(n < 0){
1519
printf(1, "cat: read error\n");
1620
exit();

0 commit comments

Comments
 (0)
Please sign in to comment.