]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/dir.cpp
Windows uses ; as separator in $PATH
[libs/core.git] / source / fs / dir.cpp
index f77584708bb20a94d01496da33465dd0ffec40c7..0b6873277d4feb014d76df62afdde602d0679698 100644 (file)
@@ -17,6 +17,15 @@ namespace FS {
 namespace
 {
 
+enum
+{
+#ifdef WIN32
+       ITEMSEP = ';'
+#else
+       ITEMSEP = ':'
+#endif
+};
+
 /** Helper function to determine the location of the program's executable.
 Caches the last result to cut down filesystem access with repeated calls. */
 const Path &get_bin_dir(const string &argv0)
@@ -30,7 +39,7 @@ const Path &get_bin_dir(const string &argv0)
                if(argv0.find('/')==string::npos)
                {
                        const char *path = getenv("PATH");
-                       vector<string> dirs = split(path, ':');
+                       vector<string> dirs = split(path, ITEMSEP);
                        for(vector<string>::const_iterator i=dirs.begin(); i!=dirs.end(); ++i)
                                if(exists(Path(*i)/argv0))
                                {
@@ -103,18 +112,18 @@ list<string> list_filtered(const Path &path, const string &filter)
 
        list<string> result;
        DIR *dir = opendir(path.str().c_str());
-       if(dir)
+       if(!dir)
+               throw system_error("opendir");
+
+       while(dirent *de = readdir(dir))
        {
-               while(dirent *de = readdir(dir))
-               {
-                       const char *fn = de->d_name;
-                       if(fn[0]=='.' && (fn[1]==0 || (fn[1]=='.' && fn[2]==0))) 
-                               continue;
-                       if(r_filter.match(fn))
-                               result.push_back(fn);
-               }
-               closedir(dir);
+               const char *fn = de->d_name;
+               if(fn[0]=='.' && (fn[1]==0 || (fn[1]=='.' && fn[2]==0))) 
+                       continue;
+               if(r_filter.match(fn))
+                       result.push_back(fn);
        }
+       closedir(dir);
 
        return result;
 }