Calculate_relative_path(): do not count trailing separator

This commit is contained in:
Thomas Bernard 2019-02-01 10:20:09 +01:00
parent b504d440a0
commit bd57e6e8ea
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -966,13 +966,15 @@ const char * Calculate_relative_path(const char * ref_path, const char * path)
return path; // no common part found return absolute path
// count the number of path separators in the reference path
for (i = last_separator; real_ref_path[i] != '\0'; i++)
if (real_ref_path[i] == PATH_SEPARATOR[0])
{
if (real_ref_path[i] == PATH_SEPARATOR[0] && real_ref_path[i + 1] != '\0') // do not count the trailing separator
separator_count++;
}
i = 0;
// construct the relative path
while(separator_count-- > 0)
i += snprintf(rel_path + i, MAX_PATH_CHARACTERS - i, "..%s", PATH_SEPARATOR);
strncpy(rel_path + i, path + last_separator + 1, MAX_PATH_CHARACTERS - i);
rel_path[MAX_PATH_CHARACTERS -1] = '\0';
rel_path[MAX_PATH_CHARACTERS - 1] = '\0';
return rel_path;
}