/* * Portable and non-broken cat(1). * * Dan Cross */ #include #include #include #include typedef unsigned char uchar; void cat(FILE *fd) { size_t n; uchar buf[8192]; while ((n = fread(buf, sizeof(uchar), sizeof(buf), fd)) > 0) { if (fwrite(buf, sizeof(uchar), n, stdout) != n) { perror("fwrite"); } } } int main(int argc, char *argv[]) { FILE *fd; char *filename; if (argc == 1) { cat(stdin); } else while ((filename = *++argv) != NULL) { if (strcmp(filename, "-") == 0) { cat(stdin); continue; } fd = fopen(filename, "rb"); if (fd == NULL) { perror(filename); continue; } cat(fd); fclose(fd); } return(EXIT_SUCCESS); }