]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/sg_dir.cxx
Fix BTG writer for non-included index arrays.
[simgear.git] / simgear / misc / sg_dir.cxx
index b8a6899119520040db94c7d7ae53febef4af8960..95929229a57a6b01647351d42ef45c4f548f1f13 100644 (file)
@@ -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;
       }
     }