From 3e0eb272a331d3d311bb172e4830c7b797af7b40 Mon Sep 17 00:00:00 2001 From: gambas Date: Wed, 11 Aug 2021 22:57:15 +0200 Subject: [PATCH] Restore the end-of-file detection for buffered streams whose read ahead is allowed. [INTERPRETER] * BUG: Standard input does not use read ahead anymore in all cases. * BUG: Restore the end-of-file detection for buffered streams whose read ahead is allowed. --- main/gbx/gbx_c_file.c | 4 ++-- main/gbx/gbx_stream_buffer.c | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/main/gbx/gbx_c_file.c b/main/gbx/gbx_c_file.c index 347cb6c54..52f32848c 100644 --- a/main/gbx/gbx_c_file.c +++ b/main/gbx/gbx_c_file.c @@ -158,11 +158,11 @@ CFILE *CFILE_create(STREAM *stream, int mode) static CFILE *create_default_stream(FILE *file, int mode) { STREAM stream; - bool tty = isatty(fileno(file)); + //bool tty = isatty(fileno(file)); CLEAR(&stream); stream.type = &STREAM_buffer; - stream.common.no_read_ahead = tty; + stream.common.no_read_ahead = TRUE; stream.common.standard = TRUE; stream.common.check_read = TRUE; stream.buffer.file = file; diff --git a/main/gbx/gbx_stream_buffer.c b/main/gbx/gbx_stream_buffer.c index a02912fad..2ae683a33 100644 --- a/main/gbx/gbx_stream_buffer.c +++ b/main/gbx/gbx_stream_buffer.c @@ -163,19 +163,20 @@ static int stream_tell(STREAM *stream, int64_t *pos) static int stream_eof(STREAM *stream) { - return !FD || feof(FD); - - /*int c; + int c; - if (!FD) + if (!FD || feof(FD) || stream->common.eof) return TRUE; - + + if (stream->common.no_read_ahead) + return FALSE; + c = fgetc(FD); if (c == EOF) return TRUE; ungetc(c, FD); - return FALSE;*/ + return FALSE; }