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

Chown

Change owner of file

Declaration

Source position: oldlinux.pp line 1397

function Chown(

  path: PathStr;

  NewUid: LongInt;

  NewGid: LongInt

):Boolean;

Description

Chownsets the User ID and Group ID of the file in Pathto NewUid, NewGidThe function returns Trueif the call was succesfull, Falseif the call failed.

Errors

Errors are returned in LinuxError.

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 Pathhas no search (=execute) permission.
sys_enoent
A directory entry in Pathdoes 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 filesystem.
sys_eloop
Pathhas a reference to a circular symbolic link, i.e. a symbolic link, whose expansion points to itself.

See also

Chmod

  

Change file permission bits

Access

  

Check file access

Example

Program Example24;

{ Program to demonstrate the Chown function. }

Uses oldlinux;

Var UID,GID : Longint;
    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 not Chown ('test.txt',UID,GID) then
    if LinuxError=Sys_EPERM then
      Writeln ('You are not root !')
    else
      Writeln ('Chmod failed with exit code : ',LinuxError)
  else
    Writeln ('Changed owner successfully !');
end.