fpReadLink
Read destination of symbolic link
Declaration
Source position: bunxh.inc line 102
function fpReadLink(name: pchar; linkname: pchar; maxlen: size_t) : cint;
function fpReadLink(const Name: RawByteString) : RawByteString;
Description
FpReadLink 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. Extended error information is returned by the FpGetErrno function.
- 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 process's memory space.
- SYS_ENOMEM
- Not enough kernel memory was available.
See also
Name | Description |
---|---|
FpSymLink | Create a symbolic link |
Example
Program Example62;
{ Program to demonstrate the ReadLink function. }
Uses BaseUnix,Unix;
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 fpSymLink ('test.txt','new.txt')<>0 then
writeln ('Error when symlinking !');
S:=fpReadLink('new.txt');
If S='' then
Writeln ('Error reading link !')
Else
Writeln ('Link points to : ',S);
{ Now remove links }
If fpUnlink ('new.txt')<>0 then
Writeln ('Error when unlinking !');
If fpUnlink ('test.txt')<>0 then
Writeln ('Error when unlinking !');
end.