This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] [mingw32] fix regresion with trailing backslashes in -Iinclude dir


On mingw32, with a command-line -I include option ending with a
backslash gcc fails to recognise an existing directory. For example,
'-I..\include\' reports a non-existent directory while '-I..\include' works.
This is a regression from 3.3.3 and is observed on both 3.4 and and

Trailing forward slashes cause no problems.

For some strange reason, the stat function in MS runtime accepts
POSIX-style '/' but not DOS-style '\\' as final character for a
directory name 

stat says these are directories:


but these raise ENOENT

"c:\\winnt\\system32\\" "c:/winnt/system32\\"

There is one exception:  A drive root dir (eg  c:/)  *must* end in a
dir_separator  and stat accepts either '/' or '\\' in this case.

The problem comes when c-incpath.c:remove_duplicates calls stats.
There used to be a call to __cpp_simplify_pathname (IIRC) that took care
of the problem but that's gone now.

The following patch fixes by canonicalizing the include path when we add
it to the include chain.  This canonicalization used to be done in
remove_duplicates, just before the call to stat, but I think add_path
is more logical place.

As side effect, this patch makes the output of -E (and -H) look a lot
tidier by getting rid of mixed '\\' and '/' in pathnames.

Tested on i685-pc-mingw32, bootstrapped with c, c++, objc.

        2004-05-29  Danny Smith  <>

        * c-incpath.c (add_path): Canonicalize paths to use '/' if

Index: c-incpath.c
RCS file: /cvs/gcc/gcc/gcc/c-incpath.c,v
retrieving revision 1.13
diff -c -3 -p -r1.13 c-incpath.c
*** c-incpath.c 5 May 2004 12:20:18 -0000 1.13
--- c-incpath.c 29 May 2004 01:05:26 -0000
*************** add_path (char *path, int chain, int cxx
*** 321,326 ****
--- 321,333 ----
    cpp_dir *p;
+   /* Convert all backslashes to slashes.  */
+   char* c;
+   for (c = path; *c; c++)
+     if (*c == '\\') *c = '/';
+ #endif
    p = xmalloc (sizeof (cpp_dir));
    p->next = NULL;
    p->name = path;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]