|
|
OpenSmalltalk
/
opensmalltalk-vm
|
Cog
|
|
Build #1261 passed
|
2 hours, 31 minutes, and 30 seconds
|
akgrant43
|
Merge pull request #232 from akgrant43/21643-FilePlugin-primitiveFileAtEnd
FilePlugin currently splits files in to two groups:
1) Stdio streams and
2) everything else.
To test for the end of file, FilePlugin>>primitiveFileAtEnd:
1) Uses feof() for stdio streams.
2) Compares the current position to the file size for everything else.
This returns the expected results for regular files, but fails for
non-regular files, e.g.:
```
(FileSystem / 'dev' / 'urandom') binaryReadStream next: 8.
'/proc/cpuinfo' asFileReference contents
```
both return empty collections.
Modify sqFileAtEnd() (FilePlugin>>primitiveFileAtEnd) so that #atEnd
returns true when the last character has been read.
Both Squeak and Pharo expect that #atEnd can be used to control
iteration over a stream, answering true as soon as the last character
has been read, and importantly not requiring #next values to be tested
for an end-of-stream.
Previously, stdio streams just used feof(), which requires reading past
the end of the stream, and so required the value returned by #next to be
tested for nil. This causes problems with streams over other
collections where nil is a valid value.
sqFileAtEnd() would also fail to return the correct value for other
files such as kernel virtual files, e.g. /proc/cpuinfo, and devices like
/dev/urandom, because they have a reported file size of 0.
This change also takes a step towards removing the special handling of
stdio files on Unix, significantly simplifying the code base.
This change doesn't break any existing code that uses #next == nil to
test for end-of-stream.
|