]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/dir.cpp
Store absolute path to argv[0] in Application
[libs/core.git] / source / fs / dir.cpp
index ffe56708bffeb85552839e6867663470b9b0a418..00385e0d52d5602251719da1f3dc61859ccaecec 100644 (file)
@@ -220,5 +220,24 @@ void chdir(const Path &path)
                throw system_error("chdir");
 }
 
                throw system_error("chdir");
 }
 
+Path path_lookup(const string &name, const list<Path> &paths)
+{
+       for(list<Path>::const_iterator i=paths.begin(); i!=paths.end(); ++i)
+       {
+               Path full = *i/name;
+               if(exists(full))
+                       return realpath(full);
+       }
+
+       return Path();
+}
+
+Path path_lookup(const string &name)
+{
+       const char *path = getenv("PATH");
+       vector<string> dirs = split(path, ITEMSEP);
+       return path_lookup(name, list<Path>(dirs.begin(), dirs.end()));
+}
+
 } // namespace FS
 } // namespace Msp
 } // namespace FS
 } // namespace Msp