summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kat.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/kat.c b/src/kat.c
index a8f8360..a80015e 100644
--- a/src/kat.c
+++ b/src/kat.c
@@ -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);
}