+FileTarget *VirtualFileSystem::find_binary(const string &name)
+{
+ SearchPath path;
+ if(const char *env_path = getenv("PATH"))
+ {
+ vector<string> parts = split(env_path, ':');
+ for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ path.push_back(*i);
+ }
+ else
+ {
+ path.push_back("/bin");
+ path.push_back("/usr/bin");
+ }
+
+ for(SearchPath::const_iterator i=path.begin(); i!=path.end(); ++i)
+ {
+ FS::Path filename = *i/name;
+ if(FileTarget *tgt = get_target(filename))
+ {
+ builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, *i, tgt->get_type()));
+ return tgt;
+ }
+ else if(file_exists(filename))
+ {
+ builder.get_logger().log("vfs", format("Binary %s found in %s", name, *i));
+ return new Executable(builder, filename);
+ }
+
+ builder.get_logger().log("vfs", format("Binary %s not found in %s", name, *i));
+ }
+
+ return 0;
+}
+