| 1 |
#include <fcntl.h> |
| 2 |
#include <unistd.h> |
| 3 |
#include <stdio.h> |
| 4 |
|
| 5 |
const int BUF_LEN = 512; |
| 6 |
|
| 7 |
|
| 8 |
int main(int argc, char** argv) |
| 9 |
{ |
| 10 |
unsigned char buf[BUF_LEN]; |
| 11 |
int fd = 0; |
| 12 |
int len = 0; |
| 13 |
|
| 14 |
|
| 15 |
for (int i = 1; i < argc; i++) { |
| 16 |
int fd = open(argv[i], O_RDONLY); |
| 17 |
if (fd < 0) { |
| 18 |
fprintf(stderr, "error opening %s: %d\n", argv[i], fd); |
| 19 |
return 1; |
| 20 |
} |
| 21 |
|
| 22 |
for (;;) { |
| 23 |
len = read(fd, &buf[0], BUF_LEN); |
| 24 |
if (len > 0) { |
| 25 |
write(STDOUT_FILENO, buf, len); |
| 26 |
} else if (len == 0) { |
| 27 |
break; |
| 28 |
} else { |
| 29 |
fprintf(stderr, "error reading %s\n", argv[i]); |
| 30 |
return 1; |
| 31 |
} |
| 32 |
} |
| 33 |
close(fd); |
| 34 |
} |
| 35 |
|
| 36 |
return 0; |
| 37 |
} |