Mail Archives: djgpp-workers/2002/06/26/11:35:09
> Hello.
> I've just been looking at the FSEXT hooks code. I noticed that symlinks are
> not handled consistently. Should the symlink be resolved, before calling a
> function that takes a path name? For instance compare
> src/libc/ansi/stdio/remove.c and src/libc/posix/sys/stat/lstat.c. lstat.c
> passes the FSEXT the resolved name. remove.c passes the FSEXT the original
> name. I haven't looked at any other cases, but I think the FSEXT docs should
> be more clear on what kind of filename an FSEXT can expect to have passed into
> it.
As I see it - FSEXT should operate on the same thing caller function
does. I.E. If open() is aware of symlinks then it should pass resolved
name to FSEXT. If _open() is not, it should pass original name.
> Actually, I have another question. How do we remove symlinks using libc?
> According to the unlink man page on RedHat Linux 6.2 unlink() should remove a
> symlink. But looking at the code for remove (and hence unlink) in our libc, it
> looks like it will always remove the target file. I think this is a bug.
I was aware that remove() operates on files themselves. I was confused
until I found this little gem piece of evidence:
http://www.delorie.com/archives/browse.cgi?p=djgpp-workers/2000/08/23/08:08:43
Here is the relevant quote by Eli:
- remove, rename, rmdir, unlink: these are indeed documented not to
follow symlinks, but this refers to the last part of the file
name, I think, not to its directory part. For example, this
call:
remove ("/foo/bar/baz/file");
should resolve symlinks in "/foo/bar/baz", in case one or more of
them are symlinks. Otherwise, `remove' will fail, because the
low-level DOS functions it calls don't know about symlinks.
So I have two functions for solving symlinks: _solve_symlinks()
which returns 100%-symlink-clean-path and _solve_dir_symlinks() which
resolve symlinks everywhere but in the last component of the path.
Which is used in the case of remove and alike. I think I screwed
up choosing the latter function name...
Laurynas
- Raw text -