gcov.c (create_file_names): Properly handle UNIX and DOS directory separators.

* 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
This commit is contained in:
Pascal Obry 2008-10-03 12:49:38 +00:00 committed by Olivier Hainque
parent b268558f8a
commit 2f07423c8c
2 changed files with 48 additions and 28 deletions

View 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

View 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), '/'));)
/* First check for leading drive separator. */
while (*pold != '\0')
{
unsigned shift = 0;
if (prev + 1 == cptr && prev[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++;
}
#endif
else if ((*pold == '/' && strstr (pold, "/./") == pold)
|| (*pold == '\\' && strstr (pold, "\\.\\") == pold))
pold += 3;
else if (*pold == '/' && strstr (pold, "/../") == pold)
{
strcpy (pnew, "/^/");
pnew += 3;
pold += 4;
}
else if (*pold == '\\' && strstr (pold, "\\..\\") == pold)
{
strcpy (pnew, "\\^\\");
pnew += 3;
pold += 4;
}
else
*cptr++ = '#';
if (shift)
{
cptr = prev;
do
prev[0] = prev[shift];
while (*prev++);
}
*pnew++ = *pold++;
}
*pnew = '\0';
}
strcat (name, ".gcov");