summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/omd.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/omd.c b/src/omd.c
index 2658687..2308d0e 100644
--- a/src/omd.c
+++ b/src/omd.c
@@ -1,7 +1,7 @@
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include "io/lines.h"
#include "util/versie.h"
@@ -48,20 +48,22 @@ static void reverse_in_place(char *buf, size_t len) {
}
static void process(const char *fname, FILE *f) {
- struct file_lines fl;
- if (!file_lines_open("omd", fname, f, &fl)) exit(1);
+ char *line = NULL;
+ size_t linen = 0;
- while (true) {
- struct string_view sv;
- if (!file_lines_read(&fl, &sv)) break;
-
- reverse_in_place(sv.s, sv.len);
- size_t nw = fwrite(sv.s, 1, sv.len, stdout);
- if (nw < sv.len) exit(1);
- putchar('\n');
+ ssize_t nread = 0;
+ while ((errno = 0, nread = getline(&line, &linen, f)) != -1) {
+ if (line[nread - 1] == '\n') nread--;
+ reverse_in_place(line, nread);
+ printf("%s", line);
}
- file_lines_close(&fl);
+ free(line);
+
+ if (errno != 0) {
+ printf("omd: fout bij lezen uit bestand '%s'\n", fname);
+ exit(1);
+ }
}
int entry_omd(int argc, char **argv) {