Sign in Join

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

Mailing lists / fpc-pascal / 2002-07

question about FileGetAttr

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

milimeter

Hello, Everyone

  under /usr/local/, I have a file of information:
  -rw-r--r-- root root aaa.dat
  so the file belongs to root, and can be read by any user.
  Then I try to test the file use another user: milimeter as following
    writeln('File Attr: ',FileGetAttr('aaa.dat'));
  then I get 32, it means it is writable. But actually, it's readonly for user milimeter. Why this result? A bug?
  Thanks for your help.
  Yours,
  mili
Yet Another Geek
Hello, Everyone under /usr/local/, I have a file of information: -rw-r--r-- root root aaa.dat so the file belongs to root, and can be read by any

user.

Then I try to test the file use another user:

milimeter as following

writeln('File Attr: ',FileGetAttr('aaa.dat')); then I get 32, it means it is writable. But actually, it's readonly
// I think something like this would be better for
Unix-type filesystems:
program permtest;
uses
  linux;
const
  theFile = '/usr/local/aaa.dat';
begin
  if access(TheFile, R_OK)
  then WriteLn('You can read this file.')
  else WriteLn('Read permission denied.');
  if access(TheFile, W_OK)
  then WriteLn('You can modify this file.')
  else WriteLn('Write permission denied.');
  if access(TheFile, X_OK)
  then WriteLn('You can execute this file')
  else WriteLn('Execute permission denied.');

if access(dirname(TheFile), F_OK)
then WriteLn('You can browse this directory')
else WriteLn('Browsing of ', dirname(TheFile) , ' is not allowed.');

end.

You can also check out the "linfiles.pas" unit in the CurlPas project.
It has wrappers around the Linux file-access and
file-type routines,
to make them a little easier to use (at least for me) http://www.houston.quik.com/jkp/curlpas

Hope this helps...
- Jeff

__________________________________________________ Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

Jonas Maebe
to milimeter: Hello, Everyone under /usr/local/, I have a file of information: -rw-r--r-- root root…
milimeter wrote 6 lines
under /usr/local/, I have a file of information: -rw-r--r-- root root aaa.dat so the file belongs to root, and can be read by any user. Then I try to test the file use another user: milimeter as following writeln('File Attr: ',FileGetAttr('aaa.dat')); then I get 32, it means it is writable. But actually, it's readonly for user milimeter. Why this result? A bug?

What makes you think that this means that the file is writable? I just looked at the source, and filegetattr() does not return the permissions of a file. It returns whether a file has the "archive" flag set (always set to true under Linux, since there is no such flag there), whether it's a directory, whether it's hidden, whether it's read-only and whether it's a system file. The appropriate bits you can test are called faArchive, faDirectory, faHidden, faReadOnly and faSysFile.

Jonas