return result;
}
+ int filterLen = nameFilter.size();
+
while (true) {
struct dirent* entry = readdir(dp);
if (!entry) {
}
// 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;
}
}
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;
}
}