A small Glk issue with external files

I was writing some rather arbitrary unit tests yesterday, and I ran into a situation where cheapglk failed to do what I expected. Investigation led me to this comment in the fopen() man page:

“ANSI C requires that a file positioning function [i.e., fseek()]) intervene between output and input, unless an input operation encounters end-of-file.”

That’s for files opened with fopen(“r+”), which I’m using for ReadWrite files. Indeed, if I open a ReadWrite Glk stream, and do a read and then a write, I get a crazy result – the data is written at the end of the file rather than at the mark.

I’m pretty sure that nobody’s ever run into this before. However, I still want to resolve it, and I’d rather not resolve it by adding this statement of limitation to the Glk spec.

Therefore, it’s the Glk library’s responsibility to work around this for the ReadWrite case. I have updated CheapGlk to do this. Patch: github.com/erkyrath/cheapglk/co … fd68c28235

Unit test: eblong.com/zarf/glulx/externalfile.ulx
Unit test source: eblong.com/zarf/glulx/externalfile.inf