X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmisc%2Fsg_dir.cxx;h=95929229a57a6b01647351d42ef45c4f548f1f13;hb=e4e31be7d43569a92a5d9fa7e784381b66cbd95a;hp=b8a6899119520040db94c7d7ae53febef4af8960;hpb=c4b4c0ce59602a0b749e22b29d6ce5db6f654eae;p=simgear.git diff --git a/simgear/misc/sg_dir.cxx b/simgear/misc/sg_dir.cxx index b8a68991..95929229 100644 --- a/simgear/misc/sg_dir.cxx +++ b/simgear/misc/sg_dir.cxx @@ -106,6 +106,8 @@ PathList Dir::children(int types, const std::string& nameFilter) const return result; } + int filterLen = nameFilter.size(); + while (true) { struct dirent* entry = readdir(dp); if (!entry) { @@ -113,7 +115,8 @@ PathList Dir::children(int types, const std::string& nameFilter) const } // skip hidden files (names beginning with '.') unless requested - if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.')) { + if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.') && + strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) { continue; } @@ -144,7 +147,13 @@ PathList Dir::children(int types, const std::string& nameFilter) const } if (!nameFilter.empty()) { - if (strstr(entry->d_name, nameFilter.c_str()) == NULL) { + int nameLen = strlen(entry->d_name); + if (nameLen < filterLen) { + continue; // name is shorter than the filter + } + + char* nameSuffix = entry->d_name + (nameLen - filterLen); + if (strcmp(nameSuffix, nameFilter.c_str())) { continue; } }