A write-protected stream can be opened in READ or in READ SHAREREAD mode, but opening in SHAREREAD mode fails.
Linein(file) works in spite of the error message.
tested release ver 4.1 under windows 32bit and ooRexx-4.2.0-7419.sles1110 64 bit.
C:\ftp>rexx rexxtry
REXX-ooRexx_4.1.0(MT) 6.03 5 Dec 2010
rexxtry.rex lets you interactively try REXX statements.
Each string is executed when you hit Enter.
Enter 'call tell' for a description of the features.
Go on - try a few... Enter 'exit' to end.
file='test2'
........................................... rexxtry.rex on WindowsNT
Say Stream(file,'c','open shareread')
READY:
........................................... rexxtry.rex on WindowsNT
Say Stream(file,'c','close')
READY:
........................................... rexxtry.rex on WindowsNT
'attrib +r test2'
rc = 0 .................................... rexxtry.rex on WindowsNT
Say Stream(file,'c','open shareread')
ERROR:13
........................................... rexxtry.rex on WindowsNT
Say Stream(file,'c','open read')
READY:
........................................... rexxtry.rex on WindowsNT
Say Stream(file,'c','open read shareread')
READY:
........................................... rexxtry.rex on WindowsNT
Anonymous
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.