There is probably some obvious solution here that I overlook...
I have minimized my problem to this tiny program:
Program OpenFile;
uses SysUtils;
Var fin : File;
begin
Assign(fin, ParamStr(1));
Reset(fin);
end.(Obviously my real program is also doing some reading from the file. I want to parse out some data from a binary file.)
Experimenting with this in FreeBSD with fpc 3.2.3. The final program will be compiled for 16-bit DOS, but I will worry about that part later. Have not tested this on any other system.
The above works fine as long as I try to use it on a file that exists and is writeable.
If I try it on a write-protected file however it fails with this error:
EInOutError: Access deniedIf I read the documentation for Reset correctly this is kind of expected behavior, as the mode used for untyped files will be "using the mode specified in filemode" and that constant is set to 2 (i.e. read/write) (
https://www.freepascal.org/docs-html/rtl/system/filemode.html)?So, without re-compiling fpc to modify that constant... how do I open a read-only file for reading? Is there some procedure I am not finding that I should use instead of Reset if I just want to read the file? I only find Rewrite and Append, but those do the opposite of what I am trying to achieve?
(I can work around this easily since luckily I can make my files read-write, so no panic for now. I preferred to keep the files read-only to avoid accidentally modifying files, but since I have everything under version control anyway if I happen to modify a file I can revert it anyway. But I am still really curious what the correct way of doing this would be.
)