Check result of write (thans to Alexander Kapshuk <alexander.kapshuk@gmail)
This commit is contained in:
parent
912575ad12
commit
89826f41bd
8
cat.c
8
cat.c
|
@ -9,8 +9,12 @@ cat(int fd)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
while((n = read(fd, buf, sizeof(buf))) > 0)
|
while((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||||
write(1, buf, n);
|
if (write(1, buf, n) != n) {
|
||||||
|
printf(1, "cat: write error\n");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
if(n < 0){
|
if(n < 0){
|
||||||
printf(1, "cat: read error\n");
|
printf(1, "cat: read error\n");
|
||||||
exit();
|
exit();
|
||||||
|
|
Loading…
Reference in a new issue