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)
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))
{
break;
}
}
- else
+
+ if(exe.empty())
exe = realpath(argv0);
last_argv0 = argv0;
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;
}
if(dir[-1]=="bin" || dir[-1]=="sbin")
return dir/".."/"share"/appname;
+ else if(dir[-1]=="MacOS")
+ return dir/".."/"Resources";
else
return dir;
}