summaryrefslogtreecommitdiff
path: root/gcc/gcov.c
diff options
context:
space:
mode:
authorhainque <hainque@138bc75d-0d04-0410-961f-82ee72b054a4>2008-10-03 12:49:38 +0000
committerhainque <hainque@138bc75d-0d04-0410-961f-82ee72b054a4>2008-10-03 12:49:38 +0000
commit1db0fa5055672380ffdf9ea32b6ef81ba166f436 (patch)
tree942aca1137183dcda1c3fc60f8db38532bc19c21 /gcc/gcov.c
parent797dd800dcdcbb1d0344bdd6d112d8b083972891 (diff)
downloadgcc-1db0fa5055672380ffdf9ea32b6ef81ba166f436.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@140854 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gcov.c')
-rw-r--r--gcc/gcov.c67
1 files changed, 40 insertions, 27 deletions
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 1c4b97db1fd..a92ce91f2a3 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -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");