-#include <cstdlib>
-#include <unistd.h>
#include <dirent.h>
#include <msp/core/application.h>
+#include <msp/core/environ.h>
#include <msp/core/systemerror.h>
#include <msp/strings/regex.h>
#include <msp/strings/utils.h>
{
Path exe;
if(argv0.find(DIRSEP)==string::npos)
- if(const char *path = getenv("PATH"))
+ {
+ string path = getenv("PATH");
+ if(!path.empty())
{
for(const string &d: split(path, ITEMSEP))
if(exists(Path(d)/argv0))
break;
}
}
+ }
if(exe.empty())
exe = realpath(argv0);
rmdir(path);
}
-list<string> list_files(const Path &path)
+vector<string> list_files(const Path &path)
{
return list_filtered(path, string());
}
-list<string> list_filtered(const Path &path, const string &filter)
+vector<string> list_filtered(const Path &path, const string &filter)
{
Regex r_filter(filter);
- list<string> result;
+ vector<string> result;
DIR *dir = opendir(path.str().c_str());
if(!dir)
throw system_error("opendir");
return dir;
}
-Path path_lookup(const string &name, const list<Path> &paths)
+Path path_lookup(const string &name, const vector<Path> &paths)
{
for(const Path &p: paths)
{
Path path_lookup(const string &name)
{
- const char *path = getenv("PATH");
- list<string> dirs = split(path, ITEMSEP);
- return path_lookup(name, list<Path>(dirs.begin(), dirs.end()));
+ string path = getenv("PATH");
+ vector<string> dirs = split(path, ITEMSEP);
+ return path_lookup(name, vector<Path>(dirs.begin(), dirs.end()));
}
} // namespace FS