Quantcast

How to check if file is a Windows symbolic link.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to check if file is a Windows symbolic link.

Erwin Waterlander
Hi,

How do I check in C if a path points to a Windows NTFS symbolic link (on
Vista and 7)?
It would be nice if this could be done with lstat() and S_ISLNK().
And how do I get the path to the target?

--
Erwin


------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to check if file is a Windows symbolic link.

lrn-2
On 23.04.2011 21:37, Erwin Waterlander wrote:
> Hi,
>
> How do I check in C if a path points to a Windows NTFS symbolic link (on
> Vista and 7)?
> It would be nice if this could be done with lstat() and S_ISLNK().
> And how do I get the path to the target?
You can't. MS Visual C Runtime (MSVCR) does not provide lstat() or
S_ISLNK or anything of the kind. MinGW C Runtime extensions do not
provide anything like that either.

Even better - simple stat() from MSVCR will NOT work properly with
symlinks if you link to msvcrt (which MinGW does by default), you have
to link to newer msvcr80 (or was it 71? I don't remember) to be able to
use CRT functions (like stat()) on symlinks transparently.

You can, obviously, use WinAPI functions to do so, but that is not
exactly "in C".

There are lstat()-and-friends implementations on top of WinAPI out
there. I know at least one (because i wrote it) - libntlink. But it's
GPL (scares off people for some reason) and it was not tested
extensively. And it's incomplete.

------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to check if file is a Windows symbolic link.

Erwin Waterlander
LRN schreef, Op 23-4-2011 20:01:

> On 23.04.2011 21:37, Erwin Waterlander wrote:
>> Hi,
>>
>> How do I check in C if a path points to a Windows NTFS symbolic link (on
>> Vista and 7)?
>> It would be nice if this could be done with lstat() and S_ISLNK().
>> And how do I get the path to the target?
> You can't. MS Visual C Runtime (MSVCR) does not provide lstat() or
> S_ISLNK or anything of the kind. MinGW C Runtime extensions do not
> provide anything like that either.
>
> Even better - simple stat() from MSVCR will NOT work properly with
> symlinks if you link to msvcrt (which MinGW does by default), you have
> to link to newer msvcr80 (or was it 71? I don't remember) to be able to
> use CRT functions (like stat()) on symlinks transparently.
>
> You can, obviously, use WinAPI functions to do so, but that is not
> exactly "in C".

OK. Thanks for the info. What are the WinAPI functions that I should use
for testing if a file is a symbolic link and to get the path to its
target? I couldn't find it. I have very little experience with WinAPI.

> There are lstat()-and-friends implementations on top of WinAPI out
> there. I know at least one (because i wrote it) - libntlink. But it's
> GPL (scares off people for some reason) and it was not tested
> extensively. And it's incomplete.
>
I'm looking for an example that I can use under FreeBSD license.

best regards,

--
Erwin Waterlander
Zeelsterstraat 59B
5652 EB Eindhoven
http://www.xs4all.nl/~waterlan/



------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to check if file is a Windows symbolic link.

lrn-2
On 24.04.2011 13:50, Erwin Waterlander wrote:

> LRN schreef, Op 23-4-2011 20:01:
>> On 23.04.2011 21:37, Erwin Waterlander wrote:
>>> Hi,
>>>
>>> How do I check in C if a path points to a Windows NTFS symbolic link (on
>>> Vista and 7)?
>>> It would be nice if this could be done with lstat() and S_ISLNK().
>>> And how do I get the path to the target?
>> You can't. MS Visual C Runtime (MSVCR) does not provide lstat() or
>> S_ISLNK or anything of the kind. MinGW C Runtime extensions do not
>> provide anything like that either.
>>
>> Even better - simple stat() from MSVCR will NOT work properly with
>> symlinks if you link to msvcrt (which MinGW does by default), you have
>> to link to newer msvcr80 (or was it 71? I don't remember) to be able to
>> use CRT functions (like stat()) on symlinks transparently.
>>
>> You can, obviously, use WinAPI functions to do so, but that is not
>> exactly "in C".
> OK. Thanks for the info. What are the WinAPI functions that I should use
> for testing if a file is a symbolic link and to get the path to its
> target? I couldn't find it. I have very little experience with WinAPI.
>
I think [1] should make a good reading.
WinAPI functions like CreateFile() and DeviceIoControl() are involved
most of the time. You should also read about Reparse Points, because
symlinks are implemented that way on NT. I think [2] might have the
right info (not sure about the license on the code there).
In some cases you're lucky, as simple WinAPI functions will give you the
info you need or will do the things you need done. Read carefully about
symlink effects on WinAPI functions in [1]

[1] http://msdn.microsoft.com/en-us/library/aa365680%28v=vs.85%29.aspx
[2] http://www.codeproject.com/KB/vista/ReparsePointID.aspx


------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to check if file is a Windows symbolic link.

Erwin Waterlander
On 04/24/2011 12:12 PM, LRN wrote:

> On 24.04.2011 13:50, Erwin Waterlander wrote:
>> OK. Thanks for the info. What are the WinAPI functions that I should use
>> for testing if a file is a symbolic link and to get the path to its
>> target? I couldn't find it. I have very little experience with WinAPI.
> I think [1] should make a good reading.
> WinAPI functions like CreateFile() and DeviceIoControl() are involved
> most of the time. You should also read about Reparse Points, because
> symlinks are implemented that way on NT. I think [2] might have the
> right info (not sure about the license on the code there).
> In some cases you're lucky, as simple WinAPI functions will give you the
> info you need or will do the things you need done. Read carefully about
> symlink effects on WinAPI functions in [1]
>
> [1] http://msdn.microsoft.com/en-us/library/aa365680%28v=vs.85%29.aspx
> [2] http://www.codeproject.com/KB/vista/ReparsePointID.aspx
>
>
Thanks.

best regards,

Erwin

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Loading...