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

Danny Smith dannysmith@clear.net.nz
Sun May 30 11:53:00 GMT 2004


From: "Zack Weinberg" <zack@codesourcery.com>


| Danny Smith <dannysmith@clear.net.nz> writes:
| 
| > Hello,
| >
| > 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
| > trunk.
| >
| > 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 
| ...
| 
| >         * c-incpath.c (add_path): Canonicalize paths to use '/' if
| >         HAVE_DOS_BASED_FILESYSTEM.
| 
| This is OK, but please add a comment explaining what you just
| discovered, so someone doesn't take it back out again.
| 

Is this sufficient?  Is OK for trunk only or for 3.4.1 as well.  

Danny

--- c-incpath.c 30 May 2004 01:39:46 -0000
*************** add_path (char *path, int chain, int cxx
*** 321,326 ****
--- 321,336 ----
  {
    cpp_dir *p;
  
+ #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+   /* Convert all backslashes to slashes.  The native CRT stat()
+      function does not recognise a directory that ends in a backslash
+      (unless it is a drive root dir, such "c:\").  Forward slashes,
+      trailing or otherwise, cause no problems for stat().  */
+   char* c;
+   for (c = path; *c; c++)
+     if (*c == '\\') *c = '/';
+ #endif
+ 
    p = xmalloc (sizeof (cpp_dir));
    p->next = NULL;
    p->name = path;

| zw



More information about the Gcc-patches mailing list