diff options
author | Lieuwe Rooijakkers <lieuwerooijakkers@gmail.com> | 2024-07-25 23:59:57 +0200 |
---|---|---|
committer | Lieuwe Rooijakkers <lieuwerooijakkers@gmail.com> | 2024-08-02 22:37:57 +0200 |
commit | 420e28845d5068d0c3b432ffc0d5fc80b7b7d7e2 (patch) | |
tree | 129119bff447ef0f86818e09407900657f597c82 | |
parent | e9c8b358027e5b0d3f4787d74957d1355f87d5bc (diff) |
rn: use getline
-rw-r--r-- | src/rn.c | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -5,7 +5,6 @@ #include <unistd.h> #include "util/versie.h" -#include "io/lines.h" static void usage(FILE *f) { fprintf(f, @@ -48,21 +47,16 @@ static char** parse_options(int argc, char **argv, bool *perFile) { static void process(const char *fname, FILE *file, bool perFile, size_t *n) { if (perFile) *n = 1; - struct file_lines fl; - if (!file_lines_open("rn", fname, file, &fl)) exit(1); - - while (true) { - struct string_view sv; - if (!file_lines_read(&fl, &sv)) break; - - printf("%6lu ", *n); - fwrite(sv.s, 1, sv.len, stdout); - printf("\n"); + char *line = NULL; + size_t linen = 0; + ssize_t nread = 0; + while ((nread = getline(&line, &linen, file)) != -1) { + printf("%6lu %s", *n, line); *n += 1; } - file_lines_close(&fl); + free(line); } int entry_rn(int argc, char **argv) { |