Sign in Join

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

Mailing lists / fpc-pascal / 2007-04

[oldlinux]: STAT_IRWXG get chmod number

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Marco van de Voort
to TOUZEAU DAVID
Is there anybody has worked with STAT_IRWXG ? http://www.freepascal.org/docs-html/rtl/oldlinux/index-2.html

That is a legacy api. Better use Baseunix:

I need infos in order to get a function that get file permissions on linux system (like 0777, 0755...)

http://www.freepascal.org/docs-html/rtl/baseunix/fpaccess.html

or via stat:

http://www.freepascal.org/docs-html/rtl/baseunix/fpstat.html

Note that you can make octal values using the & notation.

E.g.

var i :  integer;
begin
 i:=&770;
 writeln(i);
end.
TOUZEAU DAVID
to Marco van de Voort

Thanks marco for the way

i have copy the example , but how can i convert "info.st_mode" in human readable mask (0777, 0755...)
For example, a file in 0755 mask is 16877 value in info.st_mode.

best regards

unit base_unix;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,variants, Linux,BaseUnix,IniFiles,strutils;
  type
  Tunix=class
private
public
    procedure Free;
    constructor Create;
    function get_file_permission(path:string):string;
END;
implementation
constructor Tunix.Create;
begin
end;
//##############################################################################
procedure Tunix.Free;
begin
end;
function Tunix.get_file_permission(path:string):string;
var
   s:string;
   info : stat;
   i:Integer;
begin
fpstat (path,info);
writeln;
  writeln ('Result of fstat on file');
  writeln ('Inode   : ',info.st_ino);
  writeln ('Mode    : ',info.st_mode);
  writeln ('nlink   : ',info.st_nlink);
  writeln ('uid     : ',info.st_uid);
  writeln ('gid     : ',info.st_gid);
  writeln ('rdev    : ',info.st_rdev);
  writeln ('Size    : ',info.st_size);
  writeln ('Blksize : ',info.st_blksize);
  writeln ('Blocks  : ',info.st_blocks);
  writeln ('atime   : ',info.st_atime);
  writeln ('mtime   : ',info.st_mtime);
  writeln ('ctime   : ',info.st_ctime);
end;
//##############################################################################
end.
Marco van de Voort wrote 34 lines
> Is there anybody has worked with STAT_IRWXG ? > http://www.freepascal.org/docs-html/rtl/oldlinux/index-2.html > That is a legacy api. Better use Baseunix: > I need infos in order to get a function that get file permissions on > linux system (like 0777, 0755...) > http://www.freepascal.org/docs-html/rtl/baseunix/fpaccess.html or via stat: http://www.freepascal.org/docs-html/rtl/baseunix/fpstat.html Note that you can make octal values using the & notation. E.g. var i : integer; begin i:=&770; writeln(i); end. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
David Touzeau -------------------------- Linux Ubuntu Dapper 6.0.6 FreePascal-Lazarus,perl,delphi,php icq:160018849