[Overview][Constants][Types][Procedures and functions][Index] Reference for unit 'BaseUnix' (#rtl)

FpChown

Change owner of file

Declaration

Source position: bunxh.inc line 35

function FpChown(

  path: pChar;

  owner: TUid;

  group: TGid

):cint;

function FpChown(

  const path: RawByteString;

  owner: TUid;

  group: TGid

):cint;

Description

fpChown sets the User ID and Group ID of the file in Path to Owner,Group.

The function returns zero if the call was successful, a nonzero return value indicates an error.

Errors

The following error codes are returned:

sys_eperm
The effective UID doesn't match the ownership of the file, and is not zero. Owner or group were not specified correctly.
sys_eaccess
One of the directories in Path has no search (=execute) permission.
sys_enoent
A directory entry in Path does not exist or is a symbolic link pointing to a non-existent directory.
sys_enomem
Insufficient kernel memory.
sys_erofs
The file is on a read-only file system.
sys_eloop
Path has a reference to a circular symbolic link, i.e. a symbolic link, whose expansion points to itself.

See also

fpChmod

  

Change file permission bits

fpAccess

  

Check file access

Example

Program Example24;

{ Program to demonstrate the Chown function. }

Uses BaseUnix;

Var UID : TUid;
    GID : TGid;
    F : Text;

begin

  Writeln ('This will only work if you are root.');
  Write ('Enter a UID : ');readln(UID);
  Write ('Enter a GID : ');readln(GID);
  Assign (f,'test.txt');
  Rewrite (f);
  Writeln (f,'The owner of this file should become : ');
  Writeln (f,'UID : ',UID);
  Writeln (f,'GID : ',GID);
  Close (F);
  if fpChown ('test.txt',UID,GID)<>0 then
    if fpgeterrno=ESysEPERM then
      Writeln ('You are not root !')
    else
      Writeln ('Chmod failed with exit code : ',fpgeterrno)
  else
    Writeln ('Changed owner successfully !');
end.

Documentation generated on: May 14 2021