Linux file attributes(permissions) lazarus / 62-General ---------------------------------------------------------------------- lagprogramming · 2015-08-15 15:06 I don't really understand the documentation. To set the attributes(permissions) most probably I have to use BaseUnix.fpChmod. The Execute attribute can be set for owner, group and others but to read the attribute of the file I have to use BaseUnix.fpAccess. fpAccess tests for the execute attribute but it does it only for "real user ID". What's the equivalent of "real user ID" within owner, group and others?    I expect BaseUnix to be unavailable in windows. Within what ifdef do I have to enclose BaseUnix when I put it an the uses? ---------------------------------------------------------------------- marcov · 2015-08-15 16:07 ifdef:  Unix Both FPAccess and FPChMod are basically unix calls. Just look at their man pages  (without the fp- prefix): man 2  chmod or man 3 chmod  (without 2 or 3 you get the manual page for the cmdline utility of the same name) chmod sets the _filesystems_ permissions, access checks the actual permission Real user id vs effective userid is mainly related to setuid utilities. See e.g. http://www.lst.de/~okir/blackhats/node23.html ---------------------------------------------------------------------- Jonas Maebe · 2015-08-16 22:01 To read the permissions of a file, you generally use fpstat (man 2 stat). fpaccess is a shortcut for getting the permissions of the file, your own effective user and possibly group id, checking whether this combination allows you access, and in possibly checking any additional file system specific access control mechanisms (e.g., OpenAFS even completely ignores standard Unix permission flags and uses its own access control lists instead). ---------------------------------------------------------------------- lagprogramming · 2015-08-29 14:32 Code: [Select]function CopyFileAttributes(const sourcefile,destinationfile:string):boolean; //Might require {$ifdef unix}baseunix{$endif} within uses var fileinfo:{$ifdef unix}              stat;              {$endif}              {$ifdef windows}              longint;              {$endif} begin if (fileexists(sourcefile) and fileexists(destinationfile)) then    begin    {$ifdef unix}    exit((fpstat(sourcefile,fileinfo)=0)and(fpchmod(destinationfile,fil einfo.st_mode)=0));    {$endif}    {$ifdef windows}    fileinfo:=filegetattr(sourcefile);    if fileinfo>=0 then exit(filesetattr(destinationfile,fileinfo)=0);    {$endif}    end; result:=false; end;   If fpc's rtl already has such a function, you're welcome to reply it's name. If not, I'm pretty sure that you might improve this one.   In the future, I'd like a pair of cross platform functions like FileGetAttr/FileSetAttr. The fact that the pair would use data that makes sense only on the same file system, would not bother me.