Skip to content

Commit

Permalink
Attempting to scroll forward at EOF now rechecks the file size.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Sep 9, 2024
1 parent 47a7b8e commit 9933cf1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 9933cf1

Please sign in to comment.