[fpc-pascal] Target path of a SymLink file
Graeme Geldenhuys
graemeg.lists at gmail.com
Wed Aug 15 12:11:51 CEST 2007
Hi,
Is there a function in SysUtils or some other place in RTL that I can
use to extract the target path of a symlink file? I'm using
FindFirst/FindNext. The sr.Attrib and faSymLink is True, but I can't
(in a easy way) see how I can actually find out where it points to.
I'm thinking x-platform here.
Something like ExtractSymLinkPath(). :) Thinking of other available
functions like ExpandUNCFileName() or ExtractFilePath() or
ExtractRelativePath() etc..
I have the following code that works, but then I need to wrap it in
IFDEF's so it doesn't execute under Windows. I don't want IFDEF's in
my code! I'm hoping RTL has something already and just returns a
blank string for Windows, just like the faSymLink which means nothing
under Windows, yet is available.
var
info : _stat;
.....
fullname := FDirectoryName + e.Name;
if lstat(PChar(fullname),info) = 0 then
begin
e.IsLink := ((sr.Mode and $F000) = $A000);
if e.IsLink then
begin
SetLength(e.LinkTarget, MAX_PATH); // length was 256
r := libc.readlink(PChar(fullname),@(e.LinkTarget[1]),
sizeof(e.LinkTarget));
if r > 0 then
SetLength(e.LinkTarget, r)
else
e.LinkTarget := '';
libc.stat(PChar(fullname), info);
end;
Graeme.
More information about the fpc-pascal
mailing list