Mail Archives: djgpp-workers/2002/12/19/17:11:45
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 <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
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/ ]
- Raw text -