This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cpplib: Be safe in presence of symlinks
- To: Zack Weinberg <zackw at Stanford dot EDU>
- Subject: Re: cpplib: Be safe in presence of symlinks
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Date: Sun, 1 Apr 2001 10:10:25 +0100
- Cc: gcc-patches at gcc dot gnu dot org, John David Anglin <dave at hiauly1 dot hia dot nrc dot ca>
- References: <20010331213102.A20319@daikokuya.demon.co.uk> <20010401005324.G19488@stanford.edu>
Zack Weinberg wrote:-
> I'm nervous about leaving "" alone. On some systems stat("", &st)
> is an error.
It never gets to stat - see open_file (). The empty string indicates
stdin, and is handled specially. We only do fstat (), not stat (),
anyway. So I reckoned it should be OK.
> > + /* Returns true if it is safe to remove the final component of path,
> > + when it is followed by a ".." component. */
> > + static int
> > + remove_component_p (path)
> > + const char *path ATTRIBUTE_UNUSED;
> > + {
> > + #if defined (HAVE_DOS_BASED_FILE_SYSTEM) || defined (VMS)
> > + return 1;
> > + #else
> > + struct stat s;
> > +
> > + return lstat (path, &s) == 0 && S_ISDIR (s.st_mode);
> > + #endif
>
> You can't assume lstat exists. Add an autoconf probe for it. If it
> doesn't exist, assume the system has no symlinks - i.e. return 1
> always.
OK. I've not a clue how to do that, so I might learn something in the
process.
> I'm not sure that's the right thing to do if lstat returns an error.
> To come closer to the no-symlink case, ENOENT should return 1 and all
> other errors should be reported. But that may not be the right thing,
> either.
I'll think about this some more. I didn't want to start reporting
errors for something we weren't before, on the assumption that open_file
or something else will report the error if appropriate.
Neil.