diff options
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/files.c | 59 | ||||
-rw-r--r-- | libcpp/include/cpplib.h | 4 | ||||
-rw-r--r-- | libcpp/internal.h | 2 | ||||
-rw-r--r-- | libcpp/macro.c | 2 |
4 files changed, 46 insertions, 21 deletions
diff --git a/libcpp/files.c b/libcpp/files.c index 3a35f7c..6e20fc5 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1108,31 +1108,54 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, return _cpp_stack_file (pfile, file, type, loc); } -/* NAME is a header file name, find the path we'll use to open it. */ +/* NAME is a header file name, find the _cpp_file, if any. */ -const char * -cpp_find_header_unit (cpp_reader *pfile, const char *name, bool angle, - location_t loc) +static _cpp_file * +test_header_unit (cpp_reader *pfile, const char *name, bool angle, + location_t loc) { - cpp_dir *dir = search_path_head (pfile, name, angle, IT_INCLUDE); - if (!dir) - return NULL; + if (cpp_dir *dir = search_path_head (pfile, name, angle, IT_INCLUDE)) + return _cpp_find_file (pfile, name, dir, angle, _cpp_FFK_NORMAL, loc); + + return nullptr; +} - _cpp_file *file = _cpp_find_file (pfile, name, dir, angle, - _cpp_FFK_NORMAL, loc); - if (!file) - return NULL; +/* NAME is a header file name, find the path we'll use to open it and infer that + it is a header-unit. */ - if (file->fd > 0) +const char * +_cpp_find_header_unit (cpp_reader *pfile, const char *name, bool angle, + location_t loc) +{ + if (_cpp_file *file = test_header_unit (pfile, name, angle, loc)) { - /* Don't leave it open. */ - close (file->fd); - file->fd = 0; + if (file->fd > 0) + { + /* Don't leave it open. */ + close (file->fd); + file->fd = 0; + } + + file->header_unit = +1; + _cpp_mark_file_once_only (pfile, file); + + return file->path; } - file->header_unit = +1; - _cpp_mark_file_once_only (pfile, file); - return file->path; + return nullptr; +} + +/* NAME is a header file name, find the path we'll use to open it. But do not + infer it is a header unit. */ + +const char * +cpp_probe_header_unit (cpp_reader *pfile, const char *name, bool angle, + location_t loc) +{ + if (_cpp_file *file = test_header_unit (pfile, name, angle, loc)) + return file->path; + + return nullptr; } /* Retrofit the just-entered main file asif it was an include. This diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 17feb64..41d75d9 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1012,8 +1012,8 @@ extern cpp_callbacks *cpp_get_callbacks (cpp_reader *) ATTRIBUTE_PURE; extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *); extern class mkdeps *cpp_get_deps (cpp_reader *) ATTRIBUTE_PURE; -extern const char *cpp_find_header_unit (cpp_reader *, const char *file, - bool angle_p, location_t); +extern const char *cpp_probe_header_unit (cpp_reader *, const char *file, + bool angle_p, location_t); /* Call these to get name data about the various compile-time charsets. */ diff --git a/libcpp/internal.h b/libcpp/internal.h index 32f9f50..fd44de6 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -703,6 +703,8 @@ extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *, int angle, _cpp_find_file_kind, location_t); extern bool _cpp_find_failed (_cpp_file *); extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *); +extern const char *_cpp_find_header_unit (cpp_reader *, const char *file, + bool angle_p, location_t); extern void _cpp_fake_include (cpp_reader *, const char *); extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, include_type, location_t); extern bool _cpp_stack_include (cpp_reader *, const char *, int, diff --git a/libcpp/macro.c b/libcpp/macro.c index fa6acff..dff7c98 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -3010,7 +3010,7 @@ cpp_get_token_1 (cpp_reader *pfile, location_t *location) if (need_search) { - found = cpp_find_header_unit (pfile, fname, angle, tmp->src_loc); + found = _cpp_find_header_unit (pfile, fname, angle, tmp->src_loc); if (!found) found = ""; len = strlen (found); |