diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp index cb863f3..bb9f621 100644 --- a/sago/platform_folders.cpp +++ b/sago/platform_folders.cpp @@ -137,6 +137,7 @@ static std::string GetAppDataLocal() { #include // For strlen and strtok #include +#include //Typically Linux. For easy reading the comments will just say Linux but should work with most *nixes static void throwOnRelative(const char* envName, const char* envValue) { @@ -177,18 +178,17 @@ namespace sago { #if !defined(_WIN32) && !defined(__APPLE__) namespace internal { void appendExtraFoldersTokenizer(const char* envName, const char* envValue, std::vector& folders) { - std::vector buffer(envValue, envValue + std::strlen(envValue) + 1); - char* p = std::strtok ( &buffer[0], ":"); - while (p != nullptr) { - if (p[0] == '/') { - folders.push_back(p); + std::stringstream ss = std::stringstream(envValue); + std::string value; + while (std::getline(ss, value, ':')) { + if (value[0] == '/') { + folders.push_back(value); } else { //Unless the system is wrongly configured this should never happen... But of course some systems will be incorectly configured. //The XDG documentation indicates that the folder should be ignored but that the program should continue. - std::cerr << "Skipping path \"" << p << "\" in \"" << envName << "\" because it does not start with a \"/\"\n"; + std::cerr << "Skipping path \"" << value << "\" in \"" << envName << "\" because it does not start with a \"/\"\n"; } - p = std::strtok (nullptr, ":"); } } }