Mark Miesfeld - 2012-02-09

The default for opening a file is read / write if you don't specify the open mode:

"The default for OPEN is to open the stream for both reading and writing
data"

Windows won't let you open a write protected file for writing and sets the error code to:

EACCES Permission denied 13

So this is the expected behavior, not a bug.

As far as linein(file) working, this is also the expected behavior.

The stream open failed, so when linein(file) is called, the stream is not open and an implicit open is done. This is no different than if your program just had linein(file) where the file is write protected.

The interpreter first tries to open the file as read write. This fails. Then, since the operation is a read operation, the interpreter tries to open the file as read only. This succeeds and the first line is read in.