From 58f309637224d1f83a0649f66ae961df7a96a980 Mon Sep 17 00:00:00 2001 From: Andris Pavenis Date: Fri, 21 Oct 2016 18:52:25 +0300 Subject: [PATCH] re PR preprocessor/71681 (header.gcc file lookup is broken for -remap) 2016-10-21 Andris Pavenis PR preprocessor/71681 * files.c (remap_filename): Fix handling -remap in subdirectories. From-SVN: r241413 --- libcpp/ChangeLog | 5 +++++ libcpp/files.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 40bd5cdc02e..87dae8496e2 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,8 @@ +2016-10-21 Andris Pavenis + + PR preprocessor/71681 + * files.c (remap_filename): Fix handling -remap in subdirectories. + 2016-10-12 Jakub Jelinek * include/cpplib.h (struct cpp_options): Add diff --git a/libcpp/files.c b/libcpp/files.c index c8bb637fb58..e859dfe3693 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1672,7 +1672,7 @@ static char * remap_filename (cpp_reader *pfile, _cpp_file *file) { const char *fname, *p; - char *new_dir; + char *new_dir, *p3; cpp_dir *dir; size_t index, len; @@ -1701,9 +1701,15 @@ remap_filename (cpp_reader *pfile, _cpp_file *file) return NULL; len = dir->len + (p - fname + 1); - new_dir = XNEWVEC (char, len + 1); + new_dir = XNEWVEC (char, len + 2); + p3 = new_dir + dir->len; memcpy (new_dir, dir->name, dir->len); - memcpy (new_dir + dir->len, fname, p - fname + 1); + if (dir->len && !IS_DIR_SEPARATOR (dir->name[dir->len - 1])) + { + *p3++ = '/'; + len++; + } + memcpy (p3, fname, p - fname + 1); new_dir[len] = '\0'; dir = make_cpp_dir (pfile, new_dir, dir->sysp); -- 2.30.2