summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-08-02 22:45:54 +0200
committerLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-08-02 22:45:54 +0200
commitcad57de047493ec0de4faf8f9b2c8cef438e62d0 (patch)
treeb7235181a40e73453b58e3f411ce3e9681bbc2a8
parent843e6fb1a772703593ce4685cc83bdaaaba67138 (diff)
omd: use getline
-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) {