]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcov.c (create_file_names): Properly handle UNIX and DOS directory separators.
authorPascal Obry <obry@adacore.com>
Fri, 3 Oct 2008 12:49:38 +0000 (12:49 +0000)
committerOlivier Hainque <hainque@gcc.gnu.org>
Fri, 3 Oct 2008 12:49:38 +0000 (12:49 +0000)
        * gcov.c (create_file_names): Properly handle UNIX and DOS
        directory separators.
        (make_gcov_file_name): Likewise + convert the ':' DOS drive
        separator to '~' to ensure clean filenames on Windows.

From-SVN: r140854

gcc/ChangeLog
gcc/gcov.c

index 10aab9ca08aa7c77a293534dbe478e349ba8ab5b..7084d1850980dc3aa7e037931253fecd830d9136 100644 (file)
@@ -1,3 +1,10 @@
+2008-10-03  Pascal Obry  <obry@adacore.com>
+
+       * gcov.c (create_file_names): Properly handle UNIX and DOS
+       directory separators.
+       (make_gcov_file_name): Likewise + convert the ':' DOS drive
+       separator to '~' to ensure clean filenames on Windows.
+
 2008-10-02  David Edelsohn  <edelsohn@gnu.org>
 
        * config/rs6000/rs6000.c (USE_FP_FOR_ARG_P): Revert
index 1c4b97db1fd8edd56b9be5431ad1aaee6296e552..a92ce91f2a3d5a01e50bb66e5d2e93087ad942b3 100644 (file)
@@ -661,7 +661,7 @@ create_file_names (const char *file_name)
 
       base = !stat (object_directory, &status) && S_ISDIR (status.st_mode);
       strcat (name, object_directory);
-      if (base && name[strlen (name) - 1] != '/')
+      if (base && (! IS_DIR_SEPARATOR (name[strlen (name) - 1])))
        strcat (name, "/");
     }
   else
@@ -674,8 +674,8 @@ create_file_names (const char *file_name)
   if (base)
     {
       /* Append source file name.  */
-      cptr = strrchr (file_name, '/');
-      strcat (name, cptr ? cptr + 1 : file_name);
+      const char *cptr = lbasename (file_name);
+      strcat (name, cptr ? cptr : file_name);
     }
 
   /* Remove the extension.  */
@@ -1482,7 +1482,7 @@ function_summary (const coverage_t *coverage, const char *title)
 static char *
 make_gcov_file_name (const char *input_name, const char *src_name)
 {
-  char *cptr;
+  const char *cptr;
   char *name;
 
   if (flag_long_names && input_name && strcmp (src_name, input_name))
@@ -1490,8 +1490,8 @@ make_gcov_file_name (const char *input_name, const char *src_name)
       name = XNEWVEC (char, strlen (src_name) + strlen (input_name) + 10);
       name[0] = 0;
       /* Generate the input filename part.  */
-      cptr = flag_preserve_paths ? NULL : strrchr (input_name, '/');
-      strcat (name, cptr ? cptr + 1 : input_name);
+      cptr = flag_preserve_paths ? NULL : lbasename (input_name);
+      strcat (name, cptr ? cptr : input_name);
       strcat (name, "##");
     }
   else
@@ -1501,39 +1501,52 @@ make_gcov_file_name (const char *input_name, const char *src_name)
     }
 
   /* Generate the source filename part.  */
-  cptr = flag_preserve_paths ? NULL : strrchr (src_name, '/');
-  strcat (name, cptr ? cptr + 1 : src_name);
+
+  cptr = flag_preserve_paths ? NULL : lbasename (src_name);
+  strcat (name, cptr ? cptr : src_name);
 
   if (flag_preserve_paths)
     {
-      /* Convert '/' to '#', remove '/./', convert '/../' to '/^/' */
-      char *prev;
+      /* Convert '/' and '\' to '#', remove '/./', convert '/../' to '/^/',
+        convert ':' to '~' on DOS based file system.  */
+      char *pnew = name, *pold = name;
 
-      for (cptr = name; (cptr = strchr ((prev = cptr), '/'));)
-       {
-         unsigned shift = 0;
+      /* First check for leading drive separator.  */
 
-         if (prev + 1 == cptr && prev[0] == '.')
+      while (*pold != '\0')
+       {
+         if (*pold == '/' || *pold == '\\')
            {
-             /* Remove '.' */
-             shift = 2;
+             *pnew++ = '#';
+             pold++;
            }
-         else if (prev + 2 == cptr && prev[0] == '.' && prev[1] == '.')
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+         else if (*pold == ':')
            {
-             /* Convert '..' */
-             shift = 1;
-             prev[1] = '^';
+             *pnew++ = '~';
+             pold++;
            }
-         else
-           *cptr++ = '#';
-         if (shift)
+#endif
+         else if ((*pold == '/' && strstr (pold, "/./") == pold)
+                  || (*pold == '\\' && strstr (pold, "\\.\\") == pold))
+             pold += 3;
+         else if (*pold == '/' && strstr (pold, "/../") == pold)
            {
-             cptr = prev;
-             do
-               prev[0] = prev[shift];
-             while (*prev++);
+             strcpy (pnew, "/^/");
+             pnew += 3;
+             pold += 4;
            }
+         else if (*pold == '\\' && strstr (pold, "\\..\\") == pold)
+           {
+             strcpy (pnew, "\\^\\");
+             pnew += 3;
+             pold += 4;
+           }
+         else
+           *pnew++ = *pold++;
        }
+
+      *pnew = '\0';
     }
 
   strcat (name, ".gcov");