[fortran] Fix PR 55919

Submitted by Thomas Koenig on Jan. 20, 2013, 7:49 p.m.

Details

Message ID 50FC4A52.8010201@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig Jan. 20, 2013, 7:49 p.m.
Hello world,

the attached patch fixes a regression where -J dirpath/ would
issue a warning on Windows because of the trailing dir separator.

Regression-tested, but only on Linux.  I would appreciate if
somebody could also test it on Windows (and run the test case,
of course).

OK for trunk?

	Thomas

2013-01-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/55919
         * add_path_to_list:  Copy path to temporary and strip
         trailing directory separators before calling stat().

2013-01-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/55919
         * gfortran.dg/include_8.f90:  New test.

Comments

Steve Kargl Jan. 20, 2013, 10:44 p.m.
On Sun, Jan 20, 2013 at 08:49:38PM +0100, Thomas Koenig wrote:
> Hello world,
> 
> the attached patch fixes a regression where -J dirpath/ would
> issue a warning on Windows because of the trailing dir separator.
> 
> Regression-tested, but only on Linux.  I would appreciate if
> somebody could also test it on Windows (and run the test case,
> of course).
> 
> OK for trunk?
> 

The patch looks OK to me.  As this is a Windows,
hopefully someone will confirm that the patch
fixes the Windows issue before you commit.
Thomas Koenig Jan. 21, 2013, 8:41 p.m.
Hi Steve,

> The patch looks OK to me.  As this is a Windows,
> hopefully someone will confirm that the patch
> fixes the Windows issue before you commit.

Thanks!

Committed as rev. 195348 after Brad's confirmation that the
patch works on Windows.  One more regression down, 24 to go.

	Thomas

Patch hide | download patch | download mbox

Index: scanner.c
===================================================================
--- scanner.c	(Revision 195319)
+++ scanner.c	(Arbeitskopie)
@@ -310,14 +310,26 @@  add_path_to_list (gfc_directorylist **list, const
 {
   gfc_directorylist *dir;
   const char *p;
+  char *q;
   struct stat st;
+  size_t len;
+  int i;
   
   p = path;
   while (*p == ' ' || *p == '\t')  /* someone might do "-I include" */
     if (*p++ == '\0')
       return;
 
-  if (stat (p, &st))
+  /* Strip trailing directory separators from the path, as this
+     will confuse Windows systems.  */
+  len = strlen (p);
+  q = (char *) alloca (len + 1);
+  memcpy (q, p, len + 1);
+  i = len - 1;
+  while (i >=0 && IS_DIR_SEPARATOR(q[i]))
+    q[i--] = '\0';
+
+  if (stat (q, &st))
     {
       if (errno != ENOENT)
 	gfc_warning_now ("Include directory \"%s\": %s", path,