summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-18 21:53:47 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-18 21:53:47 -0400
commitf62e7ad33badfc4624c4c4cd3ed4fb0e0f5040e6 (patch)
tree9ddb7111fb2910beea2039c5fea0abb95795c1b3
parentfb7e658faa5d279d97d54e5b6c1105b3a6bdeab2 (diff)
fix repeating last line for tmpfile backed input
-rw-r--r--io.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/io.c b/io.c
index c57e6ee..6d6c328 100644
--- a/io.c
+++ b/io.c
@@ -22,7 +22,10 @@ ssize_t more_getline(struct more_file *mf, size_t lineno)
fgetpos(mf->f, &(mf->tlines[mf->nlines - 1]));
- getline(&(mf->buf), &(mf->nbuf), mf->f);
+ if (getline(&(mf->buf), &(mf->nbuf), mf->f) == -1) {
+ return -1;
+ }
+
if (mf->nlines > 1) {
mf->bytepos[mf->nlines - 1] = mf->bytepos[mf->nlines - 2] + strlen(mf->buf);
} else {
@@ -48,7 +51,7 @@ struct more_file more_open(const char *path)
if (strcmp(path, "-")) {
mf.f = fopen(path, "r");
if (!mf.f) {
- fprintf(stderr, "more: %s: %s\n", path, strerror(errno));
+ fprintf(stderr, "more: %s: %s\r\n", path, strerror(errno));
return mf;
}
}