summaryrefslogtreecommitdiffstats
path: root/gcc/c-incpath.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2003-03-02 17:44:18 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2003-03-02 17:44:18 +0000
commit03e3f0fdd00589afdab16f67722a025bab99bdca (patch)
tree59efbdcac9849427f9743e4c35cc2278aecb7295 /gcc/c-incpath.c
parent8cef25e737d97238751152631de70237a2aabaa4 (diff)
downloadppe42-gcc-03e3f0fdd00589afdab16f67722a025bab99bdca.tar.gz
ppe42-gcc-03e3f0fdd00589afdab16f67722a025bab99bdca.zip
* c-incpath.c (remove_component_p, simplify_path): Move back to
cppfiles.c. (remove_duplicates): Use cpp_simplify_path. * c-incpath.h (simplify_path): Remove. * c-lex.c: Don't include c-incpath.h. (init_c_lex): Remove simplify_path. * cppfiles.c (remove_component_p, cpp_simplify_path): Restore. (find_or_create_entry, validate_pch): Revert. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63669 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-incpath.c')
-rw-r--r--gcc/c-incpath.c156
1 files changed, 1 insertions, 155 deletions
diff --git a/gcc/c-incpath.c b/gcc/c-incpath.c
index 96bf69d7e28..b1c8de5cb3b 100644
--- a/gcc/c-incpath.c
+++ b/gcc/c-incpath.c
@@ -47,7 +47,6 @@ static void add_env_var_paths PARAMS ((const char *, int));
static void add_standard_paths PARAMS ((const char *, const char *, int));
static void free_path PARAMS ((struct cpp_path *, int));
static void merge_include_chains PARAMS ((cpp_reader *, int));
-static int remove_component_p PARAMS ((const char *));
static struct cpp_path *
remove_duplicates PARAMS ((cpp_reader *, struct cpp_path *,
struct cpp_path *, struct cpp_path *, int));
@@ -177,7 +176,7 @@ remove_duplicates (pfile, head, system, join, verbose)
int reason = REASON_QUIET;
cur = *pcur;
- simplify_path (cur->name);
+ cpp_simplify_path (cur->name);
if (stat (cur->name, &st))
{
@@ -355,156 +354,3 @@ register_include_chains (pfile, sysroot, iprefix,
cpp_set_include_chains (pfile, heads[QUOTE], heads[BRACKET],
quote_ignores_source_dir);
}
-
-/* Returns true if it is safe to remove the final component of path,
- when it is followed by a ".." component. We use lstat to avoid
- symlinks if we have it. If not, we can still catch errors with
- stat (). */
-static int
-remove_component_p (path)
- const char *path;
-{
- struct stat s;
- int result;
-
-#ifdef HAVE_LSTAT
- result = lstat (path, &s);
-#else
- result = stat (path, &s);
-#endif
-
- /* There's no guarantee that errno will be unchanged, even on
- success. Cygwin's lstat(), for example, will often set errno to
- ENOSYS. In case of success, reset errno to zero. */
- if (result == 0)
- errno = 0;
-
- return result == 0 && S_ISDIR (s.st_mode);
-}
-
-/* Simplify a path name in place, deleting redundant components. This
- reduces OS overhead and guarantees that equivalent paths compare
- the same (modulo symlinks).
-
- Transforms made:
- foo/bar/../quux foo/quux
- foo/./bar foo/bar
- foo//bar foo/bar
- /../quux /quux
- //quux //quux (POSIX allows leading // as a namespace escape)
-
- Guarantees no trailing slashes. All transforms reduce the length
- of the string. Returns PATH. errno is 0 if no error occurred;
- nonzero if an error occurred when using stat () or lstat (). */
-void
-simplify_path (path)
- char *path ATTRIBUTE_UNUSED;
-{
-#ifndef VMS
- char *from, *to;
- char *base, *orig_base;
- int absolute = 0;
-
- errno = 0;
- /* Don't overflow the empty path by putting a '.' in it below. */
- if (*path == '\0')
- return;
-
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
- /* Convert all backslashes to slashes. */
- for (from = path; *from; from++)
- if (*from == '\\') *from = '/';
-
- /* Skip over leading drive letter if present. */
- if (ISALPHA (path[0]) && path[1] == ':')
- from = to = &path[2];
- else
- from = to = path;
-#else
- from = to = path;
-#endif
-
- /* Remove redundant leading /s. */
- if (*from == '/')
- {
- absolute = 1;
- to++;
- from++;
- if (*from == '/')
- {
- if (*++from == '/')
- /* 3 or more initial /s are equivalent to 1 /. */
- while (*++from == '/');
- else
- /* On some hosts // differs from /; Posix allows this. */
- to++;
- }
- }
-
- base = orig_base = to;
- for (;;)
- {
- int move_base = 0;
-
- while (*from == '/')
- from++;
-
- if (*from == '\0')
- break;
-
- if (*from == '.')
- {
- if (from[1] == '\0')
- break;
- if (from[1] == '/')
- {
- from += 2;
- continue;
- }
- else if (from[1] == '.' && (from[2] == '/' || from[2] == '\0'))
- {
- /* Don't simplify if there was no previous component. */
- if (absolute && orig_base == to)
- {
- from += 2;
- continue;
- }
- /* Don't simplify if the previous component was "../",
- or if an error has already occurred with (l)stat. */
- if (base != to && errno == 0)
- {
- /* We don't back up if it's a symlink. */
- *to = '\0';
- if (remove_component_p (path))
- {
- while (to > base && *to != '/')
- to--;
- from += 2;
- continue;
- }
- }
- move_base = 1;
- }
- }
-
- /* Add the component separator. */
- if (to > orig_base)
- *to++ = '/';
-
- /* Copy this component until the trailing null or '/'. */
- while (*from != '\0' && *from != '/')
- *to++ = *from++;
-
- if (move_base)
- base = to;
- }
-
- /* Change the empty string to "." so that it is not treated as stdin.
- Null terminate. */
- if (to == path)
- *to++ = '.';
- *to = '\0';
-#else /* VMS */
- errno = 0;
-#endif /* !VMS */
-}
OpenPOWER on IntegriCloud