lstat() and stat()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • onLINES

    lstat() and stat()

    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?
  • Jack Klein

    #2
    Re: lstat() and stat()

    On Mon, 29 Sep 2008 19:03:37 -0700 (PDT), onLINES
    <dopelines@gmai l.comwrote in comp.lang.c:
    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?
    There are no functions named stat() or lstat() in the C standard
    library, they are extensions provided by your compiler and operating
    system. That makes them off-topic here.

    You need to ask this question in a group that supports your particular
    compiler/OS combination. Based on the headers in your post, it is
    possible that news:comp.os.ms-windows.program mer.win32 might be a good
    choice.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.l earn.c-c++

    Comment

    • Peter Nilsson

      #3
      Re: lstat() and stat()

      onLINES <dopeli...@gmai l.comwrote:
      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.

      --
      Peter

      Comment

      • Flash Gordon

        #4
        Re: lstat() and stat()

        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.progr ammer 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.progr ammer 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.
        --
        Flash Gordon
        If spamming me sent it to smap@spam.cause way.com
        If emailing me use my reply-to address
        See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/

        Comment

        • Antoninus Twink

          #5
          Re: lstat() and stat()

          On 30 Sep 2008 at 2:03, onLINES wrote:
          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.

          Comment

          • Joachim Schmitz

            #6
            Re: lstat() and stat()

            onLINES wrote:
            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


            Comment

            • Keith Thompson

              #7
              Re: lstat() and stat()

              Flash Gordon <smap@spam.caus eway.comwrites:
              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.progr ammer where there are lots of people who know about
              Unix extensions.
              [...]

              But if you ask this question on comp.unix.progr ammer, their first
              question for you will be why you didn't read the documentation first.
              So read the documentation first.

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
              Nokia
              "We must do something. This is something. Therefore, we must do this."
              -- Antony Jay and Jonathan Lynn, "Yes Minister"

              Comment

              Working...