From 12a93c3e2987126e579d18d5db4c401bbe0f2256 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 19 Aug 2019 17:33:58 +0200 Subject: [PATCH] Fix use of strtok on windows. On windows, strtok_r is called strto_s. --- src/tools/pathTools.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tools/pathTools.cpp b/src/tools/pathTools.cpp index 07eb3d4d5..65873123c 100644 --- a/src/tools/pathTools.cpp +++ b/src/tools/pathTools.cpp @@ -94,6 +94,12 @@ std::string computeRelativePath(const std::string& path, const std::string& abso return relativePath; } +#ifdef _WIN32 +# define STRTOK strtok_s +#else +# define STRTOK strtok_r +#endif + /* Warning: the relative path must be with slashes */ 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()); #endif char* saveptr = nullptr; - char* token = strtok_r(cRelativePath, "/", &saveptr); + char* token = STRTOK(cRelativePath, "/", &saveptr); while (token != NULL) { if (std::string(token) == "..") { absolutePath = removeLastPathElement(absolutePath, true, false); - token = strtok_r(NULL, "/", &saveptr); + token = STRTOK(NULL, "/", &saveptr); } else if (strcmp(token, ".") && strcmp(token, "")) { absolutePath += std::string(token); - token = strtok_r(NULL, "/", &saveptr); + token = STRTOK(NULL, "/", &saveptr); if (token != NULL) { absolutePath += SEPARATOR; } } else { - token = strtok_r(NULL, "/", &saveptr); + token = STRTOK(NULL, "/", &saveptr); } } free(cRelativePath);