Sign in Join

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

Mailing lists / fpc-pascal / 2001-09

Detecting (sym)link in fpc/Linux

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Cor Slot

Hi

How can see if a file is a link on a linux filesystem?

I'm trying to create a routine that recursively scans the filesystem with findfirst, findnext, findclose. For each file I use fstat to get info about the file.

When the program encounters a link to a directory it recurses into that directory. When the link points to the same directory as the link is in this gives an endless loop.

With the data I have from searchrec and stat, how can I determine that the current file is a link? Or do I need another function to do that?

Thanx!

Cheers,
Cor.

==============================
Cor.J. Slot Rotterdam [NL]
Voice/FAXmail +31 84 851 04 78
==============================

Reply by email

Mirek Novak
to Cor Slot

Hi,

in fpc unit linux there are defined 'POSIX macros' (as said in 'man fstat') for checking filetype
what U need is 'S_ISLNK()' see units.pdf

M.N.

Cor Slot píše:

Show quoted text 24 lines
Hi How can see if a file is a link on a linux filesystem? I'm trying to create a routine that recursively scans the filesystem with findfirst, findnext, findclose. For each file I use fstat to get info about the file. When the program encounters a link to a directory it recurses into that directory. When the link points to the same directory as the link is in this gives an endless loop. With the data I have from searchrec and stat, how can I determine that the current file is a link? Or do I need another function to do that? Thanx! Cheers, Cor. ============================== Cor.J. Slot Rotterdam [NL] Voice/FAXmail +31 84 851 04 78 ==============================

Reply by email

Cor Slot
to Mirek Novak

Hi Mirek Novak,

in fpc unit linux there are defined 'POSIX macros' (as said in 'man fstat') for checking filetype what U need is 'S_ISLNK()' see units.pdf

Aha... Thanx! That's what I needed... And I also needed to use LStat instead of FStat to get the correct results.

Thanks!

Cheers,
Cor.

==============================
Cor.J. Slot Rotterdam [NL]
Voice/FAXmail +31 84 851 04 78
==============================

Reply by email