From 9933cf193898275b3a6209029d99e1ef5482fa6c Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Mon, 9 Sep 2024 12:47:30 -0700 Subject: [PATCH] Attempting to scroll forward at EOF now rechecks the file size. --- ch.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ch.c b/ch.c index 336af779..8c344364 100644 --- a/ch.c +++ b/ch.c @@ -149,10 +149,7 @@ static int ch_get(void) struct buf *bp; struct bufnode *bn; ssize_t n; - lbool read_again; int h; - POSITION pos; - POSITION len; if (thisfile == NULL) return (EOI); @@ -224,12 +221,19 @@ static int ch_get(void) for (;;) { - pos = ch_position(ch_block, bp->datasize); + lbool read_again; + POSITION len; + POSITION pos = ch_position(ch_block, bp->datasize); if ((len = ch_length()) != NULL_POSITION && pos >= len) + { /* - * At end of file. + * Apparently at end of file. + * Double-check the file size in case it has changed. */ - return (EOI); + ch_resize(); + if ((len = ch_length()) != NULL_POSITION && pos >= len) + return (EOI); + } if (pos != ch_fpos) { @@ -599,6 +603,16 @@ public POSITION ch_length(void) return (ch_fsize); } +/* + * Check the file size, in case it has changed. + */ +public void ch_resize(void) +{ + POSITION fsize = filesize(ch_file); + if (fsize != NULL_POSITION) + ch_fsize = fsize; +} + /* * Return the current position in the file. */