#include #include #include static void do_cat(FILE* f) { char buffer[4096]; while (1) { size_t nread = fread(buffer, 1, sizeof(buffer), f); if (nread == 0) return; fwrite(buffer, 1, nread, stdout); } } int main(int argc, char** argv) { FILE* f; if (argc < 2) { do_cat(stdin); } else { for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-")) f = stdin; else { f = fopen(argv[i], "r"); if (!f) { perror(argv[i]); return 1; } } do_cat(f); if (f != stdin) fclose(f); } } }