aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.cumb.org>2000-06-28 19:03:08 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-06-28 19:03:08 +0000
commitd4506961cd58fde924aa6561e8896e18161b82ad (patch)
tree82b11e25ea2057714b83389ff3651dad11f94f5e /gcc/cppfiles.c
parent47ec19c5bb9a7992d1a5f2a561df3b47dd6ea539 (diff)
downloadgcc-d4506961cd58fde924aa6561e8896e18161b82ad.zip
gcc-d4506961cd58fde924aa6561e8896e18161b82ad.tar.gz
gcc-d4506961cd58fde924aa6561e8896e18161b82ad.tar.bz2
cppfiles.c (open_include_file): If open(2) returns EMFILE or ENFILE...
* cppfiles.c (open_include_file): If open(2) returns EMFILE or ENFILE, close all cached file descriptors and try again. (_cpp_execute_include): Keep a count of the number of times each header is included. (close_cached_fd): New function. * cpphash.h (struct include_file): Rename before to include_count; all users updated. Make include_count and sysp unsigned short. * cppinit.c (cpp_finish): If -H, report headers that could use reinclude guards. (report_missing_guard): New function. From-SVN: r34760
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 1598a3e..35d1aa6 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -60,6 +60,7 @@ static ssize_t read_with_read PARAMS ((cpp_buffer *, int, ssize_t));
static ssize_t read_file PARAMS ((cpp_buffer *, int, ssize_t));
static void destroy_include_file_node PARAMS ((splay_tree_value));
+static int close_cached_fd PARAMS ((splay_tree_node, void *));
#if 0
static void hack_vms_include_specification PARAMS ((char *));
@@ -87,6 +88,20 @@ destroy_include_file_node (v)
}
}
+static int
+close_cached_fd (n, dummy)
+ splay_tree_node n;
+ void *dummy ATTRIBUTE_UNUSED;
+{
+ struct include_file *f = (struct include_file *)n->value;
+ if (f && f->fd != -1)
+ {
+ close (f->fd);
+ f->fd = -1;
+ }
+ return 0;
+}
+
void
_cpp_init_include_table (pfile)
cpp_reader *pfile;
@@ -153,6 +168,8 @@ open_include_file (pfile, filename)
ourselves.
Special case: the empty string is translated to stdin. */
+ retry:
+
if (filename[0] == '\0')
fd = 0;
else
@@ -167,6 +184,21 @@ open_include_file (pfile, filename)
filename);
}
#endif
+ if (0
+#ifdef EMFILE
+ || errno == EMFILE
+#endif
+#ifdef ENFILE
+ || errno == ENFILE
+#endif
+ )
+ {
+ /* Too many files open. Close all cached file descriptors and
+ try again. */
+ splay_tree_foreach (pfile->all_include_files, close_cached_fd, 0);
+ goto retry;
+ }
+
/* Nonexistent or inaccessible file. Create a negative node for it. */
if (nd)
{
@@ -185,7 +217,7 @@ open_include_file (pfile, filename)
{
file = xnew (struct include_file);
file->cmacro = 0;
- file->before = 0;
+ file->include_count = 0;
file->sysp = 0;
file->foundhere = 0;
file->name = xstrdup (filename);
@@ -367,9 +399,9 @@ _cpp_execute_include (pfile, f, len, no_reinclude, search_start)
return;
/* For -M, add the file to the dependencies on its first inclusion. */
- if (!inc->before && PRINT_THIS_DEP (pfile, angle_brackets))
+ if (!inc->include_count && PRINT_THIS_DEP (pfile, angle_brackets))
deps_add_dep (pfile->deps, inc->name);
- inc->before = 1;
+ inc->include_count++;
/* Handle -H option. */
if (CPP_OPTION (pfile, print_include_names))