summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kat.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/kat.c b/src/kat.c
new file mode 100644
index 0000000..7a279d0
--- /dev/null
+++ b/src/kat.c
@@ -0,0 +1,42 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int entry_kat(int argc, char **argv) {
+ if (argc == 2 && strcmp(argv[1], "-h") == 0) {
+ fprintf(stderr, "Gebruik: kat [BESTAND]...\n"
+ "\n"
+ "Schakel BESTAND(en) aaneen naar standaard uitvoer..\n");
+ return 0;
+ }
+
+ for (int i = 1; i < argc; i++) {
+ const char *fname = argv[i];
+ int fd = open(fname, O_RDONLY);
+
+ struct stat sb;
+ if (fstat(fd, &sb) == -1) {
+ fprintf(stderr, "Kon bestand niet lezen\n");
+ return 0;
+ }
+
+ char *addr = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (addr == MAP_FAILED) {
+ fprintf(stderr, "Kon bestand niet kaarten\n");
+ return 0;
+ }
+
+ for (size_t i = 0; i < sb.st_size; i++) {
+ putchar(addr[i]);
+ }
+
+ munmap(addr, sb.st_size);
+ close(fd);
+ }
+
+ return 0;
+}