From patchwork Sun Jan 20 19:49:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [fortran] Fix PR 55919 From: Thomas Koenig X-Patchwork-Id: 213989 Message-Id: <50FC4A52.8010201@netcologne.de> To: "fortran@gcc.gnu.org" , gcc-patches Date: Sun, 20 Jan 2013 20:49:38 +0100 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 PR fortran/55919 * add_path_to_list: Copy path to temporary and strip trailing directory separators before calling stat(). 2013-01-20 Thomas Koenig PR fortran/55919 * gfortran.dg/include_8.f90: New test. 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,