Skip to content

Commit

Permalink
sqFileAtEnd() revert to previous error checking
Browse files Browse the repository at this point in the history
sqFileAtEnd() hasn't done any error checking.  However adding it has
caused a report of primitive failures where previously none occurred.
No information is given about what the error is (errno isn't set), and
because no other functions are doing error checking we can't know how
far back the error occurred.
We can't limit error checking to this call because clearerr() clears not
only the error flag, but also the end-of-file flag.
  • Loading branch information
akgrant committed Apr 9, 2018
1 parent 6bee4d2 commit 005088c
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
Expand Up @@ -131,25 +131,27 @@ static squeakFileOffsetType getSize(SQFile *f)
# define pfail() 0
#endif

sqInt
sqFileAtEnd(SQFile *f) {
sqInt sqFileAtEnd(SQFile *f) {
/* Return true if the file's read/write head is at the end of the file.
* Fail and return errno if an error in the file i/o has been flagged.
*
* libc's end of file function, feof(), returns a flag that is set by
* attempting to read past the end of the file. I.e if the last character in
* the file has been read, but not one more, feof() will return false.
* attempting to read past the end of the file. I.e if the last
* character in the file has been read, but not one more, feof() will
* return false.
*
* Smalltalk's #atEnd should return true as soon as the last character
* has been read.
*
* Smalltalk's #atEnd should return true as soon as the last character has
* been read.
* We can keep the expected behaviour of #atEnd for streams other than
* terminals by peeking for the next character in the file using
* ungetc() & fgetc(), which will set the eof-file-flag if required,
* but not advance the stream.
*
* To keep the expected behaviour of #atEnd, we can peek at the next
* character in the file using ungetc() & fgetc(), which will
* set the eof-file-flag if required, but not advance the stream.
* Terminals / consoles use feof() only, which means that #atEnd
* doesn't answer true until after the end-of-file character (Ctrl-D)
* has been read.
*/
sqInt status;
int fd;
FILE *fp;
sqInt status; int fd; FILE *fp;

if (!sqFileValid(f))
return interpreterProxy->success(false);
Expand All @@ -164,8 +166,14 @@ sqFileAtEnd(SQFile *f) {
status = feof(fp);
else if (!feof(fp)) {
status = ungetc(fgetc(fp), fp) == EOF && feof(fp);
/* Normally we should check if a file error has occurred.
* But error checking isn't occurring anywhere else,
* causing hard-to-trace failures here.
* Revert to previous behaviour of ignoring errors.
if (ferror(fp))
interpreterProxy->primitiveFailForOSError(errno); }
interpreterProxy->primitiveFail();
*/
}
else
status = true;
return pexit(status);
Expand Down

0 comments on commit 005088c

Please sign in to comment.