mirror of https://github.com/kiwix/libkiwix.git
commit
e25b27b354
|
@ -94,6 +94,12 @@ std::string computeRelativePath(const std::string& path, const std::string& abso
|
||||||
return relativePath;
|
return relativePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# define STRTOK strtok_s
|
||||||
|
#else
|
||||||
|
# define STRTOK strtok_r
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Warning: the relative path must be with slashes */
|
/* Warning: the relative path must be with slashes */
|
||||||
std::string computeAbsolutePath(const std::string& path, const std::string& relativePath)
|
std::string computeAbsolutePath(const std::string& path, const std::string& relativePath)
|
||||||
{
|
{
|
||||||
|
@ -122,20 +128,20 @@ std::string computeAbsolutePath(const std::string& path, const std::string& rela
|
||||||
char* cRelativePath = strdup(relativePath.c_str());
|
char* cRelativePath = strdup(relativePath.c_str());
|
||||||
#endif
|
#endif
|
||||||
char* saveptr = nullptr;
|
char* saveptr = nullptr;
|
||||||
char* token = strtok_r(cRelativePath, "/", &saveptr);
|
char* token = STRTOK(cRelativePath, "/", &saveptr);
|
||||||
|
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
if (std::string(token) == "..") {
|
if (std::string(token) == "..") {
|
||||||
absolutePath = removeLastPathElement(absolutePath, true, false);
|
absolutePath = removeLastPathElement(absolutePath, true, false);
|
||||||
token = strtok_r(NULL, "/", &saveptr);
|
token = STRTOK(NULL, "/", &saveptr);
|
||||||
} else if (strcmp(token, ".") && strcmp(token, "")) {
|
} else if (strcmp(token, ".") && strcmp(token, "")) {
|
||||||
absolutePath += std::string(token);
|
absolutePath += std::string(token);
|
||||||
token = strtok_r(NULL, "/", &saveptr);
|
token = STRTOK(NULL, "/", &saveptr);
|
||||||
if (token != NULL) {
|
if (token != NULL) {
|
||||||
absolutePath += SEPARATOR;
|
absolutePath += SEPARATOR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = strtok_r(NULL, "/", &saveptr);
|
token = STRTOK(NULL, "/", &saveptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(cRelativePath);
|
free(cRelativePath);
|
||||||
|
|
Loading…
Reference in New Issue