X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffs%2Fdir.cpp;h=0b6873277d4feb014d76df62afdde602d0679698;hp=57fd9368f2b311da99ea1cb3a2fc1ccdaf286510;hb=2a6afe61db5603d508468adbd538ad4e96acc3fc;hpb=609c9a508cfdc7b42c46c4f21d17639204165a00 diff --git a/source/fs/dir.cpp b/source/fs/dir.cpp index 57fd936..0b68732 100644 --- a/source/fs/dir.cpp +++ b/source/fs/dir.cpp @@ -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 dirs = split(path, ':'); + vector dirs = split(path, ITEMSEP); for(vector::const_iterator i=dirs.begin(); i!=dirs.end(); ++i) if(exists(Path(*i)/argv0)) { @@ -103,18 +112,18 @@ list list_filtered(const Path &path, const string &filter) list 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; } @@ -146,6 +155,8 @@ Path get_sys_data_dir(const string &argv0, const string &appname) if(dir[-1]=="bin" || dir[-1]=="sbin") return dir/".."/"share"/appname; + else if(dir[-1]=="MacOS") + return dir/".."/"Resources"; else return dir; }