[Overview][Constants][Types][Procedures and functions][Variables] | Reference for unit 'oldlinux' (#rtl) |
Read destination of symbolic link
Source position: line 0
function ReadLink( |
name: pchar; |
linkname: pchar; |
maxlen: LongInt |
):LongInt; |
name: PathStr |
):PathStr; |
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.
On error, the first form of the function returns -1; the second one returns an empty string. LinuxError is set to report errors:
|
Create a symbolic link |
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.
No notes exist for this page yet.