This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cpplib: Be safe in presence of symlinks


On Sun, Apr 01, 2001 at 10:10:25AM +0100, Neil Booth wrote:
> 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.

What happens if I write -I "" ?  Right now that's equivalent to -I.

On the other hand,

$ echo blah | ./cpp0
# 1 "."
blah
$

> > 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.

It's not hard.  One thing I don't know is, do all systems that have
lstat declare it in <sys/stat.h>?  If not, you may have to add a
NEED_DECLARATION_LSTAT check as well as plain HAVE_LSTAT.

Maybe you should use stat if there's no lstat, because of the example
below.

> > 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.

Since the old code didn't look at the file system at all, you could
write

#include <stdio.h/../stdlib.h>

and it would be treated equivalent to #include <stdlib.h>.  I think
you've now made this an error, which is fine by me, but does it get
reported, and if so where, and is the error message useful?  One would
hope for something with "stdio.h" and "Not a directory" in it.

Now I look at it, that example is a convincing reason to stop blindly
simplifying paths, all by itself. :-)

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]