#include #include #include #include #include #include #include #define BUF_SIZE (4096 * 4) /* Main function */ int main(int argc, char *argv[]) { int fd, sz, i; char buf[BUF_SIZE]; if (argc < 2) { printf("Usage: %s [...]\n"); return 0; } for (i = 1; i < argc; i++) { fd = open(argv[i], O_RDONLY); if (fd < 0) { printf("%s: %s: ", argv[0], argv[i]); perror(NULL); continue; } while ((sz = read(fd, buf, sizeof(buf))) > 0) { if (write(STDOUT_FILENO, buf, sz) < 0) { printf("%s: write: ", argv[0]); perror(NULL); } } if (sz < 0) { printf("%s: read: ", argv[0]); perror(NULL); } close(fd); } return 0; }