From f62e7ad33badfc4624c4c4cd3ed4fb0e0f5040e6 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 18 Apr 2022 21:53:47 -0400 Subject: fix repeating last line for tmpfile backed input --- io.c | 7 +++++-- 1 file 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; } } -- cgit v1.2.1