aboutsummaryrefslogtreecommitdiff
path: root/libcpp/files.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp/files.c')
-rw-r--r--libcpp/files.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libcpp/files.c b/libcpp/files.c
index ba52d2b..301b237 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -1131,6 +1131,37 @@ cpp_find_header_unit (cpp_reader *pfile, const char *name, bool angle,
return file->path;
}
+/* Retrofit the just-entered main file asif it was an include. This
+ will permit correct include_next use, and mark it as a system
+ header if that's where it resides. We use filesystem-appropriate
+ prefix matching of the include path to locate the main file. */
+void
+cpp_retrofit_as_include (cpp_reader *pfile)
+{
+ /* We should be the outermost. */
+ gcc_assert (!pfile->buffer->prev);
+
+ if (const char *name = pfile->main_file->name)
+ {
+ /* Locate name on the include dir path, using a prefix match. */
+ size_t name_len = strlen (name);
+ for (cpp_dir *dir = pfile->quote_include; dir; dir = dir->next)
+ if (dir->len < name_len
+ && IS_DIR_SEPARATOR (name[dir->len])
+ && !filename_ncmp (name, dir->name, dir->len))
+ {
+ pfile->main_file->dir = dir;
+ if (dir->sysp)
+ cpp_make_system_header (pfile, 1, 0);
+ break;
+ }
+ }
+
+ /* Initialize controlling macro state. */
+ pfile->mi_valid = true;
+ pfile->mi_cmacro = 0;
+}
+
/* Could not open FILE. The complication is dependency output. */
static void
open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets,