From 005088c20880b62d6c0c8d033b0c993f56ddb02b Mon Sep 17 00:00:00 2001 From: AlistairGrant Date: Mon, 9 Apr 2018 18:52:44 +0200 Subject: [PATCH] sqFileAtEnd() revert to previous error checking 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. --- .../FilePlugin/sqFilePluginBasicPrims.c | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c b/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c index 5988cae9a4..e453e69cbc 100755 --- a/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c +++ b/platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c @@ -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); @@ -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);