30 lines
607 B
C
30 lines
607 B
C
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
char buf[1024];
|
|
int n;
|
|
int fd;
|
|
|
|
if (argc == 1) {
|
|
while ((n = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
|
|
write(STDOUT_FILENO, buf, n);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
fd = open(argv[i], O_RDONLY);
|
|
if (fd < 0) {
|
|
perror(argv[i]);
|
|
continue;
|
|
}
|
|
|
|
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
|
write(STDOUT_FILENO, buf, n);
|
|
}
|
|
close(fd);
|
|
}
|
|
return 0;
|
|
} |