cppfiles.c (open_file): Fail directories silently, but with an errno of NOENT set.
* cppfiles.c (open_file): Fail directories silently, but with an errno of NOENT set. (read_include_file): Move the common exit code to the sole caller. Return an int indicating success or failure. Let open_file handle directories. (stack_include_file): If read_include_file fails, push a "null" buffer. From-SVN: r41138
This commit is contained in:
parent
8d66b99ac2
commit
7c0927142c
2 changed files with 44 additions and 30 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
2001-04-06 Neil Booth <neil@daikokuya.demon.co.uk>
|
||||||
|
|
||||||
|
* cppfiles.c (open_file): Fail directories silently, but
|
||||||
|
with an errno of NOENT set.
|
||||||
|
(read_include_file): Move the common exit code to the sole
|
||||||
|
caller. Return an int indicating success or failure. Let
|
||||||
|
open_file handle directories.
|
||||||
|
(stack_include_file): If read_include_file fails,
|
||||||
|
push a "null" buffer.
|
||||||
|
|
||||||
2001-04-05 DJ Delorie <dj@redhat.com>
|
2001-04-05 DJ Delorie <dj@redhat.com>
|
||||||
|
|
||||||
* function.h (virtuals_instantiated): Declare.
|
* function.h (virtuals_instantiated): Declare.
|
||||||
|
|
|
@ -93,7 +93,7 @@ static struct include_file *
|
||||||
find_include_file PARAMS ((cpp_reader *, const cpp_token *,
|
find_include_file PARAMS ((cpp_reader *, const cpp_token *,
|
||||||
enum include_type));
|
enum include_type));
|
||||||
static struct include_file *open_file PARAMS ((cpp_reader *, const char *));
|
static struct include_file *open_file PARAMS ((cpp_reader *, const char *));
|
||||||
static void read_include_file PARAMS ((cpp_reader *, struct include_file *));
|
static int read_include_file PARAMS ((cpp_reader *, struct include_file *));
|
||||||
static void stack_include_file PARAMS ((cpp_reader *, struct include_file *));
|
static void stack_include_file PARAMS ((cpp_reader *, struct include_file *));
|
||||||
static void purge_cache PARAMS ((struct include_file *));
|
static void purge_cache PARAMS ((struct include_file *));
|
||||||
static void destroy_node PARAMS ((splay_tree_value));
|
static void destroy_node PARAMS ((splay_tree_value));
|
||||||
|
@ -241,15 +241,23 @@ open_file (pfile, filename)
|
||||||
|
|
||||||
if (file->fd != -1 && fstat (file->fd, &file->st) == 0)
|
if (file->fd != -1 && fstat (file->fd, &file->st) == 0)
|
||||||
{
|
{
|
||||||
/* Mark a regular, zero-length file never-reread now. */
|
/* If it's a directory, we return null and continue the search
|
||||||
if (S_ISREG (file->st.st_mode) && file->st.st_size == 0)
|
as the file we're looking for may appear elsewhere in the
|
||||||
{
|
search path. */
|
||||||
_cpp_never_reread (file);
|
if (S_ISDIR (file->st.st_mode))
|
||||||
close (file->fd);
|
errno = ENOENT;
|
||||||
file->fd = -1;
|
else
|
||||||
}
|
{
|
||||||
|
/* Mark a regular, zero-length file never-reread now. */
|
||||||
|
if (S_ISREG (file->st.st_mode) && file->st.st_size == 0)
|
||||||
|
{
|
||||||
|
_cpp_never_reread (file);
|
||||||
|
close (file->fd);
|
||||||
|
file->fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't issue an error message if the file doesn't exist. */
|
/* Don't issue an error message if the file doesn't exist. */
|
||||||
|
@ -284,13 +292,19 @@ stack_include_file (pfile, inc)
|
||||||
if (CPP_OPTION (pfile, print_deps) > deps_sysp && !inc->include_count)
|
if (CPP_OPTION (pfile, print_deps) > deps_sysp && !inc->include_count)
|
||||||
deps_add_dep (pfile->deps, inc->name);
|
deps_add_dep (pfile->deps, inc->name);
|
||||||
|
|
||||||
|
/* Not in cache? */
|
||||||
|
if (! DO_NOT_REREAD (inc) && ! inc->buffer)
|
||||||
|
{
|
||||||
|
/* If an error occurs, do not try to read this file again. */
|
||||||
|
if (read_include_file (pfile, inc))
|
||||||
|
_cpp_never_reread (inc);
|
||||||
|
close (inc->fd);
|
||||||
|
inc->fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (! DO_NOT_REREAD (inc))
|
if (! DO_NOT_REREAD (inc))
|
||||||
{
|
{
|
||||||
/* Not in cache? */
|
|
||||||
if (! inc->buffer)
|
|
||||||
read_include_file (pfile, inc);
|
|
||||||
len = inc->st.st_size;
|
len = inc->st.st_size;
|
||||||
|
|
||||||
if (pfile->buffer)
|
if (pfile->buffer)
|
||||||
{
|
{
|
||||||
/* We don't want MI guard advice for the main file. */
|
/* We don't want MI guard advice for the main file. */
|
||||||
|
@ -328,17 +342,17 @@ stack_include_file (pfile, inc)
|
||||||
If fd points to a plain file, we might be able to mmap it; we can
|
If fd points to a plain file, we might be able to mmap it; we can
|
||||||
definitely allocate the buffer all at once. If fd is a pipe or
|
definitely allocate the buffer all at once. If fd is a pipe or
|
||||||
terminal, we can't do either. If fd is something weird, like a
|
terminal, we can't do either. If fd is something weird, like a
|
||||||
block device or a directory, we don't want to read it at all.
|
block device, we don't want to read it at all.
|
||||||
|
|
||||||
Unfortunately, different systems use different st.st_mode values
|
Unfortunately, different systems use different st.st_mode values
|
||||||
for pipes: some have S_ISFIFO, some S_ISSOCK, some are buggy and
|
for pipes: some have S_ISFIFO, some S_ISSOCK, some are buggy and
|
||||||
zero the entire struct stat except a couple fields. Hence we don't
|
zero the entire struct stat except a couple fields. Hence we don't
|
||||||
even try to figure out what something is, except for plain files,
|
even try to figure out what something is, except for plain files
|
||||||
directories, and block devices.
|
and block devices.
|
||||||
|
|
||||||
FIXME: Flush file cache and try again if we run out of memory. */
|
FIXME: Flush file cache and try again if we run out of memory. */
|
||||||
|
|
||||||
static void
|
static int
|
||||||
read_include_file (pfile, inc)
|
read_include_file (pfile, inc)
|
||||||
cpp_reader *pfile;
|
cpp_reader *pfile;
|
||||||
struct include_file *inc;
|
struct include_file *inc;
|
||||||
|
@ -402,11 +416,6 @@ read_include_file (pfile, inc)
|
||||||
cpp_error (pfile, "%s is a block device", inc->name);
|
cpp_error (pfile, "%s is a block device", inc->name);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (S_ISDIR (inc->st.st_mode))
|
|
||||||
{
|
|
||||||
cpp_error (pfile, "%s is a directory", inc->name);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 8 kilobytes is a sensible starting size. It ought to be
|
/* 8 kilobytes is a sensible starting size. It ought to be
|
||||||
|
@ -430,19 +439,13 @@ read_include_file (pfile, inc)
|
||||||
inc->st.st_size = offset;
|
inc->st.st_size = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
close (inc->fd);
|
|
||||||
inc->buffer = buf;
|
inc->buffer = buf;
|
||||||
inc->fd = -1;
|
return 0;
|
||||||
return;
|
|
||||||
|
|
||||||
perror_fail:
|
perror_fail:
|
||||||
cpp_error_from_errno (pfile, inc->name);
|
cpp_error_from_errno (pfile, inc->name);
|
||||||
fail:
|
fail:
|
||||||
/* Do not try to read this file again. */
|
return 1;
|
||||||
close (inc->fd);
|
|
||||||
inc->fd = -1;
|
|
||||||
_cpp_never_reread (inc);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -617,6 +620,7 @@ handle_missing_header (pfile, fname, angle_brackets)
|
||||||
/* We will try making the RHS pfile->buffer->sysp after 3.0. */
|
/* We will try making the RHS pfile->buffer->sysp after 3.0. */
|
||||||
int print_dep = CPP_PRINT_DEPS(pfile) > (angle_brackets
|
int print_dep = CPP_PRINT_DEPS(pfile) > (angle_brackets
|
||||||
|| pfile->system_include_depth);
|
|| pfile->system_include_depth);
|
||||||
|
|
||||||
if (CPP_OPTION (pfile, print_deps_missing_files) && print_dep)
|
if (CPP_OPTION (pfile, print_deps_missing_files) && print_dep)
|
||||||
{
|
{
|
||||||
if (!angle_brackets || IS_ABSOLUTE_PATHNAME (fname))
|
if (!angle_brackets || IS_ABSOLUTE_PATHNAME (fname))
|
||||||
|
|
Loading…
Add table
Reference in a new issue