Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-10

cross os symbolic link handling

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

is there any function or set of functions for handling symbolic links inside the file system at an os independant level in fpcs libraries?

Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk files upt to XP and AFAIR Windows Vista has some other stuff I don't know about yet.

What I'd need would be sth. like:

function IsLink(<filehandle or name>): boolean;
function GetLinkTarget(<filehandle or name>): <filehandle or name>;

Any help on this topic is welcome ... ;)

TIA,
Marc

Michael Van Canneyt
to Marc Santhoff
Marc Santhoff wrote 15 lines
Hi, is there any function or set of functions for handling symbolic links inside the file system at an os independant level in fpcs libraries? Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk files upt to XP and AFAIR Windows Vista has some other stuff I don't know about yet. What I'd need would be sth. like: function IsLink(<filehandle or name>): boolean; function GetLinkTarget(<filehandle or name>): <filehandle or name>; Any help on this topic is welcome ... ;)

Fpc 2.3.1 supports faSymLink in the FindFirst/FindNext series of calls. If it is included in the attributes, then symbolic links are included as symbolic links and not as the file/dir they refer to.

This works cross-platform. So you could do something like

function IsLink(AFileName : string): boolean;
Var
  Info : TSearchRec;
begin
  Result:=FindFirst(AFileName,faSymLink,info)=0;
  If Result then
    begin
    Result:=(info.attr and faSymLink)=faSymLink;
    FindClose(info);
    end;
end;

Michael.

Marc Santhoff
to Michael Van Canneyt
Michael Van Canneyt wrote 22 lines
On Fri, 31 Oct 2008, Marc Santhoff wrote: > Hi, > > is there any function or set of functions for handling symbolic links > inside the file system at an os independant level in fpcs libraries? > > Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk > files upt to XP and AFAIR Windows Vista has some other stuff I don't > know about yet. > > What I'd need would be sth. like: > > function IsLink(<filehandle or name>): boolean; > function GetLinkTarget(<filehandle or name>): <filehandle or name>; > > Any help on this topic is welcome ... ;) Fpc 2.3.1 supports faSymLink in the FindFirst/FindNext series of calls. If it is included in the attributes, then symbolic links are included as symbolic links and not as the file/dir they refer to.

That's the key part of the information, and good news to me. :)

Show quoted text 15 lines
This works cross-platform. So you could do something like function IsLink(AFileName : string): boolean; Var Info : TSearchRec; begin Result:=FindFirst(AFileName,faSymLink,info)=0; If Result then begin Result:=(info.attr and faSymLink)=faSymLink; FindClose(info); end; end;

That part is easily solvable if writing one function per od type is not necessary.

Many thanks,
Marc

Tomas Hajny
to Marc Santhoff: is there any function or set of functions for handling symbolic links inside the file…

On 31 Oct 08, at 17:49, Marc Santhoff wrote:

Hi,

Show quoted text 6 lines
is there any function or set of functions for handling symbolic links inside the file system at an os independant level in fpcs libraries? Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk files upt to XP and AFAIR Windows Vista has some other stuff I don't know about yet.

.
.

.lnk files under Windows don't really work as symlinks and thus wouldn't be supported at the RTL level (they aren't directly treated like that by the Windows API level AFAIK, they're only handled by the Windows GUI). NTFS links (available since Win2k IIRC) are another story, those are much closer to the Unix symbolic link concept.

Tomas

Marc Santhoff
to Tomas Hajny
Tomas Hajny wrote 17 lines
On 31 Oct 08, at 17:49, Marc Santhoff wrote: Hi, > is there any function or set of functions for handling symbolic links > inside the file system at an os independant level in fpcs libraries? > > Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk > files upt to XP and AFAIR Windows Vista has some other stuff I don't > know about yet. . . .lnk files under Windows don't really work as symlinks and thus wouldn't be supported at the RTL level (they aren't directly treated like that by the Windows API level AFAIK, they're only handled by the Windows GUI).

I expected behaviour like that, but I need to retrieve some information on the target file of the .lnk. I'm sure some shell- or winapi-funktion will help me there.

NTFS links (available since Win2k IIRC) are another story, those are much closer to the Unix symbolic link concept.

I see, this is the new part. So I have to go searching Bills KB for that stuff.

Thank you,
Marc