Don't collapse // → / in compress_path(), and avoid generating // in the first place

This commit is contained in:
Juhani Krekelä 2021-04-20 03:26:05 +03:00
parent eb9111646e
commit 70e751e46a
1 changed files with 6 additions and 7 deletions

View File

@ -62,6 +62,7 @@ char *p;
* compress_path
*
* This assumes sizeof(char) == 1 which is probably a really bad idea.
* ^ actually that's guaranteed by C standard -nortti, 2021
*/
char *
compress_path(mp, c, cwd)
@ -78,7 +79,10 @@ char *cwd;
if (*cwd != '/') return(NULL);
r = (char *)MPGet(mp, strlen("/") + strlen(c) + strlen(cwd) + 1);
strcpy(r, cwd);
strcat(r, "/");
// Only add the slash if we don't already have one
// That is, if cwd ends in a slash, don't add an extra one
if (r[strlen(cwd) - 1] != '/')
strcat(r, "/");
strcat(r, c);
}
else r = MPStrDup(mp, c);
@ -88,12 +92,7 @@ char *cwd;
if (*p == '/')
{
p1 = p + 1;
if (*p1 == '/')
{
memmove(p, p1, strlen(p1) + 1);
continue;
}
else if (*p1 == '.')
if (*p1 == '.')
{
p2 = p1 + 1;
if (*p2 == '/')