summaryrefslogtreecommitdiff
path: root/src/kat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kat.c')
-rw-r--r--src/kat.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/kat.c b/src/kat.c
index 7a279d0..9c50aed 100644
--- a/src/kat.c
+++ b/src/kat.c
@@ -6,6 +6,8 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "util/map.h"
+
int entry_kat(int argc, char **argv) {
if (argc == 2 && strcmp(argv[1], "-h") == 0) {
fprintf(stderr, "Gebruik: kat [BESTAND]...\n"
@@ -16,26 +18,13 @@ int entry_kat(int argc, char **argv) {
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;
- }
+ struct map *map = open_map(fname);
- for (size_t i = 0; i < sb.st_size; i++) {
- putchar(addr[i]);
+ for (size_t i = 0; i < map->sb.st_size; i++) {
+ putchar(map->addr[i]);
}
- munmap(addr, sb.st_size);
- close(fd);
+ close_map(map);
}
return 0;