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

ReadLink

Read destination of symbolic link

Declaration

Source position: line 0

function ReadLink(

  name: pchar;

  linkname: pchar;

  maxlen: LongInt

):LongInt;

function ReadLink(

  name: PathStr

):PathStr;

Description

ReadLink returns the file the symbolic link name is pointing to. The first form of this function accepts a buffer linkname of length maxlen where the filename will be stored. It returns the actual number of characters stored in the buffer.

The second form of the function returns simply the name of the file.

Errors

On error, the first form of the function returns -1; the second one returns an empty string. LinuxError is set to report errors:

SYS_ENOTDIR
A part of the path in Name is not a directory.
SYS_EINVAL
maxlen is not positive, or the file is not a symbolic link.
SYS_ENAMETOOLONG
A pathname, or a component of a pathname, was too long.
SYS_ENOENT
the link name does not exist.
SYS_EACCES
No permission to search a directory in the path
SYS_ELOOP
Too many symbolic links were encountered in translating the pathname.
SYS_EIO
An I/O error occurred while reading from the file system.
SYS_EFAULT
The buffer is not part of the the process's memory space.
SYS_ENOMEM
Not enough kernel memory was available.

See also

SymLink

  

Create a symbolic link

Example

Program Example62;

{ Program to demonstrate the ReadLink function. }

Uses oldlinux;

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 not SymLink ('test.txt','new.txt') then
    writeln ('Error when symlinking !');
  S:=ReadLink('new.txt');
  If S='' then
    Writeln ('Error reading link !')
  Else
    Writeln ('Link points to : ',S);
 { Now remove links }
 If not Unlink ('new.txt') then
   Writeln ('Error when unlinking !');
 If not Unlink ('test.txt') then
   Writeln ('Error when unlinking !');
end.
The latest version of this document can be found at lazarus-ccr.sourceforge.net.