eof is a problematic operation for Streams as its state may be decided
by reading input (in sockets for instance).
Because of that, operations relying on it may read one extra byte at the
end of a file, causing the apparition of bad characters (null byte, or
replacement character).
By changing the semantic of eof and making it blocking, we ensure that
querying eof will always produce the appropriate error.
Signed-off-by: Lucas Bajolet <lucas.bajolet@gmail.com>
end
redef fun eof do
- if lookahead_length != 0 then
- return false
+ var fl = _file
+ if fl == null then return true
+ if fl.address_is_null then return true
+ if last_error != null then return true
+ if super then
+ if last_error != null then return true
+ return fl.feof
end
- return _file.as(not null).feof
+ return false
end
# Open the file at `path` for reading.
# Is there something to read.
# This function returns 'false' if there is something to read.
- fun eof: Bool is abstract
+ fun eof: Bool do
+ if lookahead_length > 0 then return false
+ lookahead_length = raw_read_bytes(lookahead, 1)
+ return lookahead_length <= 0
+ end
# Read the next sequence of non whitespace characters.
#