[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

akgrant43 notifications at github.com
Tue Apr 3 08:22:13 UTC 2018


Hi Nicolas and Dave,

> We still have ungetc to just skip: -1 even on a pipe, as long as called only once.
> This could be used to test atEndNow in precondition, Am I wrong?

You're correct (as I understand it).  I think it is more a matter of
what do we want to try and move to in the long term.

Right now the behaviour of #atEnd is:

- True after moving past the end for stdio files
- True when at the end for regular (disk) files
- Broken for non-regular files

So we already have both behaviours.

My natural inclination is to minimise the primitive code and let the
image handle it.  In this case, that means keeping the feof() behaviour
and eventually changing the definition for regular files.

The primitive should also be checking ferror(), so should be
something like (untested):


sqInt
sqFileAtEnd(SQFile *f) {
	sqInt status;
	/* Return true if the file's read/write head is at the end of the file. */

	if (!sqFileValid(f))
		return interpreterProxy->success(false);
	pentry(sqFileAtEnd);
	/* Regular files test based on current position vs size,
	 * all other files use feof() */
	if (f->isStdioStream || !S_ISREG(f->st_mode))
		status = feof(getFile(f))
	else
		status = ftell(getFile(f)) >= getSize(f);
	if (ferror(getFile(f)))
		primitiveFailForOSError(errno);
	return pexit(status);
}

Cheers,
Alistair

-- 
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-378168866
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20180403/a2afbb4c/attachment-0001.html>


More information about the Vm-dev mailing list