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

FpLink

Create a hard link to a file

Declaration

Source position: bunxh.inc line 32

function FpLink(

  existing: PChar;

  newone: PChar

):cint;

function FpLink(

  const existing: RawByteString;

  const newone: RawByteString

):cint;

Description

fpLink makes NewOne point to the same file als Existing. The two files then have the same inode number. This is known as a 'hard' link. The function returns zero if the call was succesfull, and returns a non-zero value if the call failed.

Errors

The following error codes are returned:

sys_exdev
Existing and NewOne are not on the same filesystem.
sys_eperm
The filesystem containing Existing and NewOne doesn't support linking files.
sys_eaccess
Write access for the directory containing NewOne is disallowed, or one of the directories in Existing or NewOne has no search (=execute) permission.
sys_enoent
A directory entry in Existing or NewOne does not exist or is a symbolic link pointing to a non-existent directory.
sys_enotdir
A directory entry in Existing or NewOne is nor a directory.
sys_enomem
Insufficient kernel memory.
sys_erofs
The files are on a read-only filesystem.
sys_eexist
NewOne already exists.
sys_emlink
Existing has reached maximal link count.
sys_eloop
existing or NewOne has a reference to a circular symbolic link, i.e. a symbolic link, whose expansion points to itself.
sys_enospc
The device containing NewOne has no room for another entry.
sys_eperm
Existing points to . or .. of a directory.

See also

fpSymLink

  

Create a symbolic link

fpUnLink

  

Unlink (i.e. remove) a file.

Example

Program Example21;

{ Program to demonstrate the Link and UnLink functions. }

Uses BaseUnix;

Var F : Text;
    S : String;
begin
  Assign (F,'test.txt');
  Rewrite (F);
  Writeln (F,'This is written to test.txt');
  Close(f);
  { new.txt and test.txt are now the same file }
  if fpLink ('test.txt','new.txt')<>0 then
    writeln ('Error when linking !');
  { Removing test.txt still leaves new.txt }
  If fpUnlink ('test.txt')<>0 then
    Writeln ('Error when unlinking !');
  Assign (f,'new.txt');
  Reset (F);
  While not EOF(f) do
    begin
    Readln(F,S);
    Writeln ('> ',s);
    end;
 Close (f);
 { Remove new.txt also }
 If not FPUnlink ('new.txt')<>0 then
   Writeln ('Error when unlinking !');
end.

Documentation generated on: Sep 28 2017