summaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-15 22:03:37 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-15 22:03:37 +0000
commit90e51f9eb4663d1bc9f454350f95245b05c071e2 (patch)
tree22bb40e4e927cc0a66b7d99d38172818823e8835 /gcc/cppfiles.c
parent648fb7469753f7d785415f596c2b250c635db9ad (diff)
downloadgcc-90e51f9eb4663d1bc9f454350f95245b05c071e2.tar.gz
* cppfiles.c (open_include_file): New function.
(find_include_file, cpp_read_file): Use it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32568 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 98b79af9966..bc137a93708 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -48,7 +48,7 @@ static int find_include_file PARAMS ((cpp_reader *, const char *,
struct file_name_list *,
IHASH **, int *));
static int read_include_file PARAMS ((cpp_reader *, int, IHASH *));
-
+static inline int open_include_file PARAMS ((cpp_reader *, const char *));
#if 0
static void hack_vms_include_specification PARAMS ((char *));
@@ -61,13 +61,6 @@ static void hack_vms_include_specification PARAMS ((char *));
#define INCLUDE_LEN_FUDGE 0
#endif
-/* Open files in nonblocking mode, so we don't get stuck if someone
- clever has asked cpp to process /dev/rmt0. read_include_file
- will check that we have a real file to work with. Also take care
- not to acquire a controlling terminal by mistake (this can't happen
- on sane systems, but paranoia is a virtue). */
-#define OMODES O_RDONLY|O_NONBLOCK|O_NOCTTY
-
/* Calculate hash of an IHASH entry. */
static unsigned int
hash_IHASH (x)
@@ -182,6 +175,29 @@ file_cleanup (pbuf, pfile)
return 0;
}
+/* Centralize calls to open(2) here. This provides a hook for future
+ changes which might, e.g. look for and open a precompiled version
+ of the header. It also means all the magic currently associated
+ with calling open is in one place, and if we ever need more, it'll
+ be in one place too.
+
+ Open files in nonblocking mode, so we don't get stuck if someone
+ clever has asked cpp to process /dev/rmt0. read_include_file
+ will check that we have a real file to work with. Also take care
+ not to acquire a controlling terminal by mistake (this can't happen
+ on sane systems, but paranoia is a virtue).
+
+ Use the three-argument form of open even though we aren't
+ specifying O_CREAT, to defend against broken system headers. */
+
+static inline int
+open_include_file (pfile, filename)
+ cpp_reader *pfile ATTRIBUTE_UNUSED;
+ const char *filename;
+{
+ return open (filename, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
+}
+
/* Search for include file FNAME in the include chain starting at
SEARCH_START. Return -2 if this file doesn't need to be included
(because it was included already and it's marked idempotent),
@@ -216,13 +232,13 @@ find_include_file (pfile, fname, search_start, ihash, before)
*before = 1;
*ihash = ih;
- return open (ih->name, OMODES);
+ return open_include_file (pfile, ih->name);
}
if (path == ABSOLUTE_PATH)
{
name = (char *) fname;
- f = open (name, OMODES);
+ f = open_include_file (pfile, name);
}
else
{
@@ -238,7 +254,7 @@ find_include_file (pfile, fname, search_start, ihash, before)
if (CPP_OPTIONS (pfile)->remap)
name = remap_filename (pfile, name, path);
- f = open (name, OMODES);
+ f = open_include_file (pfile, name);
#ifdef EACCES
if (f == -1 && errno == EACCES)
{
@@ -629,7 +645,7 @@ cpp_read_file (pfile, fname)
if (*fname == '\0')
f = 0;
else
- f = open (fname, OMODES);
+ f = open_include_file (pfile, fname);
return read_include_file (pfile, f, ih);
}
@@ -1193,7 +1209,7 @@ hack_vms_include_specification (fullname)
if (check_filename_before_returning)
{
- f = open (fullname, OMODES);
+ f = open (fullname, O_RDONLY|O_NONBLOCK);
if (f >= 0)
{
/* The file name is OK as it is, so return it as is. */