#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int fd;
char buf[256];
int len;
if (argc != 2) {
printf("usage:./mycat [filename]\n");
return (1);
}
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
perror("open");
return (1);
}
while (1) {
len = read(fd,buf,sizeof(buf));
if (len > 0){
write (1, buf, len);
} else if (len == 0){
break;
} else {
perror("read");
return (1);
}
}
close(fd);
return (0);
}