diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kat.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -4,7 +4,7 @@ #include <unistd.h> #include "util/versie.h" -#include "util/loop_files.h" +#include "util/loop_args.h" #include "io/read_file.h" static void usage(FILE *f) { @@ -40,16 +40,25 @@ static char** parse_options(int argc, char **argv) { return argv + optind; } -static int process(struct filebuf *fb, char*, bool) { - fwrite(fb->buf, 1, fb->sz, stdout); - free_filebuf(fb); +static int process(char *fname, bool isstdin) { +#define BUF_SIZE 4096 + + static char buf[BUF_SIZE]; + + FILE *stream = isstdin ? stdin : fopen(fname, "rb"); + + while (!feof(stream)) { + const size_t n = fread(buf, 1, BUF_SIZE, stream); + fwrite(buf, 1, n, stdout); + } + + if (!isstdin) fclose(stream); return 0; -} -// TODO: be smarter, kat doesn't have to read the whole file in memory (for -// unmappable files) +#undef BUF_SIZE +} int entry_kat(int argc, char **argv) { char **args = parse_options(argc, argv); - return loop_files(args, process); + return loop_args(args, process); } |