[PATCH] fix issue with dependency generation on win32

Nathan Froyd froydnj@codesourcery.com
Fri May 4 20:58:00 GMT 2007


On Fri, May 04, 2007 at 01:14:08PM -0700, Brian Dessent wrote:
> Nathan Froyd wrote:
> 
> >         * c-incpath.c (add_path): Move path canonicalization to...
> >         (remove_duplicates): ...here.  Use lrealpath() to perform the
> >         canonicalization and strip trailing slashes so stat() doesn't
> >         fail.
> 
> It looks like this may also fix PR22133 (which has been sitting around
> waiting to be fixed for almost two years!)

Hmmm, I didn't know about that PR!

>From the SourceForge page referenced in the PR, it sounds like the issue
is fixed with the attached patch, which is shorter and cleaner.  Testing
locally on a W2K3 box indicates that the patch works with the dependency
generation problem I showed earlier (and it also works with cases such
as '-Iinclude\\', which my patch did not).

On the same page, Danny invited somebody to submit it to gcc-patches,
since he does not have an XP/W2K box to test against.  Since I do have
one here, I'm submitting the patch on his behalf.  (Consider the
previous patch withdrawn, please.)  OK to commit if testing completes
with no regressions?

-Nathan

2007-05-04  Danny Smith  <dannysmith@users.sourceforge.net>
	    Nathan Froyd  <froydnj@codesourcery.com>

	PR/22133
	* c-incpath.c (add_path): Strip trailing path separators.
-------------- next part --------------
Index: gcc/c-incpath.c
===================================================================
--- gcc/c-incpath.c	(revision 124420)
+++ gcc/c-incpath.c	(working copy)
@@ -389,13 +389,18 @@ add_path (char *path, int chain, int cxx
   cpp_dir *p;
 
 #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
-  /* Convert all backslashes to slashes.  The native CRT stat()
-     function does not recognize 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 = '/';
+  /* Remove unnecessary trailing slashes.  On some versions of MS
+     Windows, trailing  _forward_ slashes cause no problems for stat().
+     On newer versions, stat() does not recognise a directory that ends
+     in a '\\' or '/', unless it is a drive root dir, such as "c:/",
+     where it is obligatory.  */
+  int pathlen = strlen (path);
+  char* end = path + pathlen - 1;
+  /* Preserve the lead '/' or lead "c:/".  */
+  char* start = path + (pathlen > 2 && path[1] == ':' ? 3 : 1);
+  
+  for (; end > start && IS_DIR_SEPARATOR (*end); end--)
+    *end = 0;
 #endif
 
   p = XNEW (cpp_dir);


More information about the Gcc-patches mailing list