[fpc-pascal] [oldlinux]: STAT_IRWXG get chmod number

TOUZEAU DAVID david.touzeau at fr.kaspersky.com
Sun Apr 1 23:07:27 CEST 2007


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 a écrit :
>> 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  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
>   

-- 
David Touzeau -------------------------- Linux Ubuntu Dapper 6.0.6 
FreePascal-Lazarus,perl,delphi,php icq:160018849




More information about the fpc-pascal mailing list