#include #include #include #include static void do_cat(StringView path) { FILE* f; if (path == "-") f = stdin; else { f = fopen(path.chars(), "r"); if (!f) { perror(path.chars()); exit(1); } } char buffer[4096]; while (1) { size_t nread = fread(buffer, 1, sizeof(buffer), f); if (nread == 0) return; fwrite(buffer, 1, nread, stdout); } if (f != stdin) fclose(f); } int main(int argc, char** argv) { StringView filename; os::ArgumentParser parser; parser.add_positional_argument(filename, "file"_sv, "-"_sv); Vector extra_files = parser.parse(argc, argv).value(); do_cat(filename); for (auto file : extra_files) { do_cat(file); } }