Sender: rich AT phekda DOT freeserve DOT co DOT uk Message-ID: <3E02432B.EF550904@phekda.freeserve.co.uk> Date: Thu, 19 Dec 2002 22:07:39 +0000 From: Richard Dawe X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.23 i586) X-Accept-Language: de,fr MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com Subject: Re: Bugs in __solve_symlinks References: <200212192013 DOT gBJKDm125557 AT brother DOT ludd DOT luth DOT se> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Hello. Martin Str|mberg wrote: > > According to Richard Dawe: > > * It doesn't cope with symlinks that point to themselves. For instance: > > > > ln -s a a > > > > Try to stat the file 'a'. It fails with ELOOP, but it should return > > information about the file 'a'. > > Are you sure? From the description of stat in draft D7 of the new POSIX standard by the Austin Group: "If the named file is a symbolic link, the stat( ) function shall continue pathname resolution using the contents of the symbolic link, and shall return information pertaining to the resulting file if the file exists." So if I stat 'a' above, I would expect it to resolve the symlink to 'a' and then return information about the symlink 'a', e.g.: the st_mode field would have the S_IFLNK bit set. Hmmm, it doesn't work that on Linux. Test program: ---Start teststat.c--- #include #include #include #include int main (int argc, char *argv[]) { struct stat sbuf; int ret, i; for (i = 1; i < argc; i++) { ret = stat(argv[i], &sbuf); if (ret < 0) perror(argv[0]); } return(EXIT_SUCCESS); } ---End teststat.c--- iolanthe:~ =] ln -nsf a a iolanthe:~ =] ls -l a lrwxrwxrwx 1 rich rich 1 Dec 19 22:05 a -> a iolanthe:~ =] ./src/tmp/teststat a ./src/tmp/teststat: Too many levels of symbolic links I guess I read the standard wrong. Sorry. The left 'a' in 'a -> a' above is bright blue, to indicate that the link is satisfied. An equivalent test with DJGPP shows the left 'a' in black on a red background, indicating that the link is broken. I wonder why that is. Bye, Rich =] -- Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]