mirror of https://git.qorg11.net/k9core.git
fix cat to return error if the read fails
This commit is contained in:
parent
470c684c82
commit
84715bc3d4
|
@ -16,12 +16,17 @@ cat(int fd, const char *filename)
|
|||
if(fd != 0)
|
||||
fd = open(filename, O_RDONLY);
|
||||
|
||||
if (fd == -1)
|
||||
if (fd == -1) {
|
||||
fprintf(stderr,"error opening %s: %s\n",
|
||||
filename,strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
while((c = read(fd,buf,sizeof(buf))) > 0)
|
||||
while((c = read(fd,buf,sizeof(buf))) > 0) {
|
||||
if(c == -1)
|
||||
return -1;
|
||||
write(1,buf,c);
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue