#include #include #include #include #include #include #define BUFSIZE 1 /* use this instead of BUFSIZ to see how slow direct i/o is */ void error(char *fmt, ...); int main(int argc, char *argv[]) { int fd, n; char buf[BUFSIZ]; if (argc == 1) error("please specify at least one file"); while (--argc > 0) { ++argv; if ((fd=open(*argv, O_RDONLY, 0)) == -1) error("unable to open file: %s", *argv); while ((n=read(fd, buf, BUFSIZ)) > 0) { if (write(1, buf, n) != n) error("error writing file: %s", *argv); } if (n < 0) error("error reading file: %s", *argv); } return 0; } void error(char *fmt, ...) { va_list args; va_start(args, fmt); fprintf(stderr, "error: "); vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); va_end(args); exit(1); }