]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/sg_dir.cxx
hla: Use HLADataElementIndices for HLAInteractionClass.
[simgear.git] / simgear / misc / sg_dir.cxx
index 8922b030e0d038ca506a46c85b094532f6173284..0aea771bfd004f6926fe25abbc1f373ca0031f40 100644 (file)
@@ -23,6 +23,8 @@
 #endif
 
 #include <simgear/misc/sg_dir.hxx>
+#include <math.h>
+#include <stdlib.h>
 
 #ifdef _WIN32
 #  define WIN32_LEAN_AND_MEAN
@@ -40,7 +42,9 @@
 #include <boost/foreach.hpp>
 
 #include <cstring>
+#include <cstdlib>
 #include <iostream>
+#include <algorithm> // for std::sort
 
 using std::string;
 
@@ -96,11 +100,14 @@ Dir Dir::tempDir(const std::string& templ)
     char buf[1024];
     const char* tempPath = ::getenv("TMPDIR");
     if (!tempPath) {
-        tempPath = "/tmp/";
+        tempPath = "/tmp";
     }
+    SGPath p(tempPath);
+    p.append(templ);
     // Mac OS-X / BSD manual says any number of 'X's, but GLibc manual
     // says exactly six, so that's what I'm going with
-    ::snprintf(buf, 1024, "%s%s-XXXXXX", tempPath, templ.c_str());
+    p.concat("-XXXXXX");
+    ::snprintf(buf, 1024, "%s", p.c_str());
     if (!mkdtemp(buf)) {
         SG_LOG(SG_IO, SG_WARN, "mkdtemp failed:" << strerror(errno));
         return Dir();
@@ -118,6 +125,11 @@ Dir Dir::tempDir(const std::string& templ)
 #endif
 }
 
+static bool pathSortPredicate(const SGPath& p1, const SGPath& p2)
+{
+  return p1.file() < p2.file();
+}
+
 PathList Dir::children(int types, const std::string& nameFilter) const
 {
   PathList result;
@@ -235,6 +247,11 @@ PathList Dir::children(int types, const std::string& nameFilter) const
   
   closedir(dp);
 #endif
+
+  // File system order is random. Make things deterministic,
+  // so it's the same for every user.
+  std::sort(result.begin(), result.end(), pathSortPredicate);
+
   return result;
 }
 
@@ -265,7 +282,7 @@ bool Dir::create(mode_t mode)
     
 // recursively create parent directories
     Dir pr(parent());
-    if (!pr.exists()) {
+    if (!pr.path().isNull() && !pr.exists()) {
         bool ok = pr.create(mode);
         if (!ok) {
             return false;