Skip to content

Commit

Permalink
Update bios_vhd.cpp
Browse files Browse the repository at this point in the history
fixes a couple corner cases, where files are in different disks or in the same directory
  • Loading branch information
maxpat78 committed Aug 5, 2024
1 parent c9599a4 commit 31a0d99
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ints/bios_vhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*
*/

// returns the path of "base" in a form relative to "child", where both exist
// returns the path of "base" in a form relative to "child"
char* calc_relative_path(const char* base, const char* child) {
#ifndef WIN32
char abs_base[PATH_MAX];
Expand All @@ -76,15 +76,21 @@ char* calc_relative_path(const char* base, const char* child) {
// strips common subpath, if any
while(*p++ == *q++);
p--, q--;
// returns base if they don't share anything
if(!strcmp(p, abs_base)) return strdup(base);
x = q;
// count slashes
while(*x) {
if(*x == '/' || *x == '\\') n++;
x++;
}
// allocates space for the resulting string
y = (char*)malloc(strlen(q) + n * 3); // n * strlen("..\\")
y = (char*)malloc(strlen(q) + n * 3 + 2); // n * strlen("..\\")
z = y;
if(!n) {
strcpy(z, ".\\");
z += 2;
}
while(n--) {
strcpy(z, "..\\");
z += 3;
Expand Down

0 comments on commit 31a0d99

Please sign in to comment.