summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-19 21:12:30 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-19 21:12:30 -0400
commit312c003e12d24cd1c3834978bc2f29534e384b91 (patch)
tree257543be6d71913eca59a20c6bc454805ca0c0a7
parentbd9f014a7108d0a0293ee4c44332ec5659c64313 (diff)
fix repeating last line on piped input
-rw-r--r--more.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/more.c b/more.c
index b3bbfb6..5c0de59 100644
--- a/more.c
+++ b/more.c
@@ -52,6 +52,7 @@ struct more_file {
char *buf;
size_t nbuf;
char *path;
+ int eof;
};
static int more_clear = 0;
@@ -82,6 +83,8 @@ static ssize_t more_getline(struct more_file *mf, size_t lineno)
fgetpos(mf->f, &(mf->tlines[mf->nlines - 1]));
if (getline(&(mf->buf), &(mf->nbuf), mf->f) == -1) {
+ mf->nlines--;
+ mf->eof = 1;
return -1;
}