Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-07

filesize

8 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adam Naumowicz

Hello,

I've just found out, to my horror, that a tiny program like here:

program tester;
var f:file of char;
begin
   assign(f,'testfile');
   reset(f);
   writeln(FileSize(f));
   close(f);
end.

raises error #5 (File access denied) on FileSize when the owner of 'testfile' is different from the caller but the caller has read permision for it. The same appears when I use 1.0.6 [2002/05/23] on Linux and 1.0.6 [2002/04/29] on Solaris. Is it already reported (and corrected, hopefuly)?

Best regards,
Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Jonas Maebe
to Adam Naumowicz
Adam Naumowicz wrote 13 lines
var f:file of char; begin assign(f,'testfile'); reset(f); writeln(FileSize(f)); close(f); end. raises error #5 (File access denied) on FileSize when the owner of 'testfile' is different from the caller but the caller has read permision for it. The same appears when I use 1.0.6 [2002/05/23] on Linux and 1.0.6 [2002/04/29] on Solaris. Is it already reported (and corrected, hopefuly)?

It's been reported a lot of times already (in several variants), but it is not a bug. Typed and untyped files and are by default always opened in READ/WRITE mode when using reset (just like in Turbo Pascal) contrary to text files, which are opened in read-only mode in that case. Look up the "filemode" variable in the manual for information on how to fix this problem.

Jonas

Adam Naumowicz
to Jonas Maebe
Jonas Maebe wrote 6 lines
It's been reported a lot of times already (in several variants), but it is not a bug. Typed and untyped files and are by default always opened in READ/WRITE mode when using reset (just like in Turbo Pascal) contrary to text files, which are opened in read-only mode in that case. Look up the "filemode" variable in the manual for information on how to fix this problem.

Thanks, I was misled as the error was caused by an operation on the file (FileSize in this situation) which shouldn't do any attempt to write to a file. That's why I expected it would not raise errors no matter in what mode the file was reset.
Regards,
Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Jonas Maebe
to Adam Naumowicz
Adam Naumowicz wrote
Thanks, I was misled as the error was caused by an operation on the file (FileSize in this situation) which shouldn't do any attempt to write to a file. That's why I expected it would not raise errors no matter in what mode the file was reset.

Strange, when I just tested it, the error was caused by reset.

Jonas

Martyn Ranyard
to Adam Naumowicz: I've just found out, to my horror, that a tiny program like here: program tester; var…

Aha - you will find that the same is true under DOS where the file is marked read-only.

To open a file for read-only access, you need to set FileMode (to I believe 0, but it's been a long time), as reset by default opens read-write.

Martyn

Adam Naumowicz wrote 31 lines
Hello, I've just found out, to my horror, that a tiny program like here: program tester; var f:file of char; begin assign(f,'testfile'); reset(f); writeln(FileSize(f)); close(f); end. raises error #5 (File access denied) on FileSize when the owner of 'testfile' is different from the caller but the caller has read permision for it. The same appears when I use 1.0.6 [2002/05/23] on Linux and 1.0.6 [2002/04/29] on Solaris. Is it already reported (and corrected, hopefuly)? Best regards, Adam Naumowicz -------------------------------------- WWW: http://math.uwb.edu.pl/~adamn/ -------------------------------------- _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Adam Naumowicz
to Jonas Maebe: Strange, when I just tested it, the error was caused by reset. Jonas
Jonas Maebe wrote 8 lines
On Wed, 24 Jul 2002, Adam Naumowicz wrote: > Thanks, I was misled as the error was caused by an operation on the file > (FileSize in this situation) which shouldn't do any attempt to write to > a file. That's why I expected it would not raise errors no matter in > what mode the file was reset. Strange, when I just tested it, the error was caused by reset.

That is really strange :-)
On my system the prog below runs without errors.

program tester;
var f:file of char;
begin
   filemode:=0;
   assign(f,'/etc/passwd');
   reset(f);
//   writeln(FileSize(f));
   close(f);
end.

GDB located the error at FileSize, so that was while I said so. Therefore my question is still valid - should a call to a routine as FileSize or Read cause an error when a FileMode is default ? I checked that the same test program doesn't complain when compiled with GPC, with Kylix error #13 is raised.

Regards,
Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Jonas Maebe
to Adam Naumowicz: That is really strange :-) On my system the prog below runs without errors. program…
Adam Naumowicz wrote 11 lines
> Strange, when I just tested it, the error was caused by reset. That is really strange :-) On my system the prog below runs without errors. program tester; var f:file of char; begin filemode:=0;

Here you set filemode to 0, so it's normal that this runs without error.

Show quoted text 7 lines
assign(f,'/etc/passwd'); reset(f); // writeln(FileSize(f)); close(f); end. GDB located the error at FileSize, so that was while I said so.

Did you compile it with IO checking on? (-Ci, or add {$i+} at the top) Try also compiling with -gl, then the program will write out the position in the source where the problem occurred.

Therefore my question is still valid - should a call to a routine as FileSize or Read cause an error when a FileMode is default ?

Yes, if you have read-only access to that file, but the error should already happen right after the the reset call. Since the file isn't successfully opened, the read/filesize/... will also produce errors since they're called to operate on an unopened file.

I checked that the same test program doesn't complain when compiled with GPC, with Kylix error #13 is raised.

GPC isn't a very good reference, since it's TP compatibility isn't that good. I don't have a clue what error #13 is supposed to be.

Jonas