Why C readlink() has ELOOP as a possible error









up vote
1
down vote

favorite












Background



I read about the Open Group Specification about readlink(), and there is an error called ELOOP, which indicates "A loop exists in symbolic links encountered during resolution of the path argument.", so I assume this function will continue path resolution until encountering a non-link file.



However, I did an experiment and found that readlink() only resolve the passed in path argument and just stops there but not keep resolving until reaching a non-link file.



My Problem



  1. If it's for realpath(), that makes all the sense to have ELOOP as a possible error. But why does ELOOP even exist for readlink() while it only resolves the path once?

  2. I saw this on the spec "The [ELOOP] optional error condition is added to align with the IEEE P1003.1a draft standard", does that mean the behavior of readlink() (whether it keeps resolving until reaching a non-link file) depends on implementation?

my gcc version is 8.2.1










share|improve this question



























    up vote
    1
    down vote

    favorite












    Background



    I read about the Open Group Specification about readlink(), and there is an error called ELOOP, which indicates "A loop exists in symbolic links encountered during resolution of the path argument.", so I assume this function will continue path resolution until encountering a non-link file.



    However, I did an experiment and found that readlink() only resolve the passed in path argument and just stops there but not keep resolving until reaching a non-link file.



    My Problem



    1. If it's for realpath(), that makes all the sense to have ELOOP as a possible error. But why does ELOOP even exist for readlink() while it only resolves the path once?

    2. I saw this on the spec "The [ELOOP] optional error condition is added to align with the IEEE P1003.1a draft standard", does that mean the behavior of readlink() (whether it keeps resolving until reaching a non-link file) depends on implementation?

    my gcc version is 8.2.1










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Background



      I read about the Open Group Specification about readlink(), and there is an error called ELOOP, which indicates "A loop exists in symbolic links encountered during resolution of the path argument.", so I assume this function will continue path resolution until encountering a non-link file.



      However, I did an experiment and found that readlink() only resolve the passed in path argument and just stops there but not keep resolving until reaching a non-link file.



      My Problem



      1. If it's for realpath(), that makes all the sense to have ELOOP as a possible error. But why does ELOOP even exist for readlink() while it only resolves the path once?

      2. I saw this on the spec "The [ELOOP] optional error condition is added to align with the IEEE P1003.1a draft standard", does that mean the behavior of readlink() (whether it keeps resolving until reaching a non-link file) depends on implementation?

      my gcc version is 8.2.1










      share|improve this question















      Background



      I read about the Open Group Specification about readlink(), and there is an error called ELOOP, which indicates "A loop exists in symbolic links encountered during resolution of the path argument.", so I assume this function will continue path resolution until encountering a non-link file.



      However, I did an experiment and found that readlink() only resolve the passed in path argument and just stops there but not keep resolving until reaching a non-link file.



      My Problem



      1. If it's for realpath(), that makes all the sense to have ELOOP as a possible error. But why does ELOOP even exist for readlink() while it only resolves the path once?

      2. I saw this on the spec "The [ELOOP] optional error condition is added to align with the IEEE P1003.1a draft standard", does that mean the behavior of readlink() (whether it keeps resolving until reaching a non-link file) depends on implementation?

      my gcc version is 8.2.1







      c symlink readlink






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 14:09









      melpomene

      55.8k54387




      55.8k54387










      asked Nov 10 at 13:58









      David Chen

      4891614




      4891614






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          readlink gives you the immediate target of a symbolic link. But what if resolving the path to the symbolic link involves another symlink?



          Take readlink("/foo/bar") as an example. It's supposed to return the link target of bar, but if /foo is a symlink pointing to itself, you'll get ELOOP because readlink has to resolve the directory part before getting to the final entry.



          See also man path_resolution.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239691%2fwhy-c-readlink-has-eloop-as-a-possible-error%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            readlink gives you the immediate target of a symbolic link. But what if resolving the path to the symbolic link involves another symlink?



            Take readlink("/foo/bar") as an example. It's supposed to return the link target of bar, but if /foo is a symlink pointing to itself, you'll get ELOOP because readlink has to resolve the directory part before getting to the final entry.



            See also man path_resolution.






            share|improve this answer
























              up vote
              3
              down vote



              accepted










              readlink gives you the immediate target of a symbolic link. But what if resolving the path to the symbolic link involves another symlink?



              Take readlink("/foo/bar") as an example. It's supposed to return the link target of bar, but if /foo is a symlink pointing to itself, you'll get ELOOP because readlink has to resolve the directory part before getting to the final entry.



              See also man path_resolution.






              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                readlink gives you the immediate target of a symbolic link. But what if resolving the path to the symbolic link involves another symlink?



                Take readlink("/foo/bar") as an example. It's supposed to return the link target of bar, but if /foo is a symlink pointing to itself, you'll get ELOOP because readlink has to resolve the directory part before getting to the final entry.



                See also man path_resolution.






                share|improve this answer












                readlink gives you the immediate target of a symbolic link. But what if resolving the path to the symbolic link involves another symlink?



                Take readlink("/foo/bar") as an example. It's supposed to return the link target of bar, but if /foo is a symlink pointing to itself, you'll get ELOOP because readlink has to resolve the directory part before getting to the final entry.



                See also man path_resolution.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 14:03









                melpomene

                55.8k54387




                55.8k54387



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239691%2fwhy-c-readlink-has-eloop-as-a-possible-error%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3

                    Museum of Modern and Contemporary Art of Trento and Rovereto