]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/sg_dir.cxx
Removal of PLIB/SG from SimGear
[simgear.git] / simgear / misc / sg_dir.cxx
index 74b493edf95f8b07054b6d540816bf8bfff04641..e912b2d1af01e29585542faf12d1534f80ebca12 100644 (file)
@@ -29,6 +29,8 @@
 #  include <dirent.h>
 #endif
 
+#include <sys/stat.h>
+
 #include <simgear/debug/logstream.hxx>
 
 #include <cstring>
@@ -78,6 +80,12 @@ PathList Dir::children(int types, const std::string& nameFilter) const
     }
     
     if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+         if (types & NO_DOT_OR_DOTDOT) {
+               if (!strcmp(fData.cFileName,".") || !strcmp(fData.cFileName,"..")) {
+                 continue;
+               }
+         }
+
       if (!(types & TYPE_DIR)) {
         continue;
       }
@@ -110,8 +118,14 @@ PathList Dir::children(int types, const std::string& nameFilter) const
     if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.')) {
       continue;
     }
-        
-    if (entry->d_type == DT_DIR) {
+    
+    struct stat s;
+    if (stat(file(entry->d_name).c_str(), &s)) {
+      continue; // stat() failed
+    }
+    
+    if (S_ISDIR(s.st_mode)) {
+      // directory handling
       if (!(types & TYPE_DIR)) {
         continue;
       }
@@ -121,14 +135,16 @@ PathList Dir::children(int types, const std::string& nameFilter) const
           continue;
         }
       }
-    } else if (entry->d_type == DT_REG) {
+    } else if (S_ISREG(s.st_mode)) {
+      // regular file handling
       if (!(types & TYPE_FILE)) {
         continue;
       }
     } else {
-      continue; // ignore char/block devices, fifos, etc
+      // block device /fifo/char file, ignore
+      continue;
     }
-    
+
     if (!nameFilter.empty()) {
       if (strstr(entry->d_name, nameFilter.c_str()) == NULL) {
         continue;
@@ -144,6 +160,27 @@ PathList Dir::children(int types, const std::string& nameFilter) const
   return result;
 }
 
+bool Dir::exists() const
+{
+#ifdef _WIN32
+  struct _stat buf ;
+
+  if (_stat (_path.c_str(), &buf ) < 0) {
+    return false;
+  }
+  
+  return ((S_IFDIR & buf.st_mode ) !=0);
+#else
+  struct stat buf ;
+
+  if (stat(_path.c_str(), &buf ) < 0) {
+    return false ;
+  }
+  
+  return ((S_ISDIR(buf.st_mode )) != 0);
+#endif
+}
+
 SGPath Dir::file(const std::string& name) const
 {
   SGPath childPath = _path;