summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-08-02 22:36:51 +0200
committerLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2024-08-02 22:38:00 +0200
commit843e6fb1a772703593ce4685cc83bdaaaba67138 (patch)
treed216e38a69bfa8c217cb5d02a2d18d83cf2de82c
parentc4ccd4e0798a7ed9af6f86d9819b309575d418a0 (diff)
tak: lees errno
-rw-r--r--src/rn.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/rn.c b/src/rn.c
index be4fed9..5d05322 100644
--- a/src/rn.c
+++ b/src/rn.c
@@ -1,3 +1,4 @@
+#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -51,12 +52,17 @@ static void process(const char *fname, FILE *file, bool perFile, size_t *n) {
size_t linen = 0;
ssize_t nread = 0;
- while ((nread = getline(&line, &linen, file)) != -1) {
+ while ((errno = 0, nread = getline(&line, &linen, file)) != -1) {
printf("%6lu %s", *n, line);
*n += 1;
}
free(line);
+
+ if (errno != 0) {
+ printf("tak: fout bij lezen uit bestand '%s'\n", fname);
+ exit(1);
+ }
}
int entry_rn(int argc, char **argv) {