lstat() and stat()

O

onLINES

I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?
 
P

Peter Nilsson

onLINES said:
I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE)
it's because it hit a broken link?
If that is not the case, then how can i retrieve
information on either a broken link, or even a soft link?

lstat is not a standard C function. I suggest you take your
question to POSIX or *nix group. I also suggest you RTM and
Google your question before posting.
 
F

Flash Gordon

onLINES wrote, On 30/09/08 03:03:
I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?

stat and stat are not part of the C standard. They are, however,
extensions provided on Unix. So I suggest you ask on
comp.unix.programmer where there are lots of people who know about Unix
extensions.

It is possible that someone here will provide what looks like a useful
answer, but as the real experts are not here but over in
comp.unix.programmer there is a real possibility that any errors on what
they say won't be corrected (or better solutions be pointed out) and
such errors might not show up until you try demonstrating the code to
your boss.
 
A

Antoninus Twink

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?

You are quite mistaken. lstat() will stat the symlink itself, and not
the file that it refers to. Since it therefore never tries to follow the
link, how could it know it's broken?

If you try to stat() a broken link, stat() will return -1 and set errno
to indicate that there is no such file or directory.

The stat(2) manpage lists all the possible things errno can be set to.
 
J

Joachim Schmitz

onLINES said:
I'm running into an issue.

To my understanding, when lstat() returns -1 (FAILURE) it's because it
hit a broken link?

As per my understanding (of the POSIX manual page of lstat) your
understanding is wrong
If that is not the case, then how can i retrieve information on either
a broken link, or even a soft link?

[OT]
Assuming you mean the lstat from POSIX:
Whether the filename fed to lstat() is a symbolic link is encoded into
st_mode, which will have S_IFLINK set in this case.
stat() will report an error if operating on an orphaned symbolic link, so
first call lstat(), check whether st_mode has S_IFLINK set, then call stat
and check whether it fails with ernno set to ENOENT
[/OT]

Bye, Jojo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top