diff options
Diffstat (limited to 'file.cpp')
-rw-r--r-- | file.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -2,6 +2,10 @@ #include <unordered_set> +#include <libreichwein/stringhelper.h> + +#include "env.h" + namespace fs = std::filesystem; const fs::path YMakefile{"YMakefile"}; @@ -29,3 +33,31 @@ std::filesystem::path simplified_path(const std::filesystem::path& p) } return p; } + +bool is_executable(const std::string& file) { + std::vector<std::string> paths {Reichwein::Stringhelper::split(env_value("PATH"), ":")}; + + for (const auto& i: paths) { + fs::path path{i + "/" + file}; + if (fs::exists(path) && (fs::status(path).permissions() & std::filesystem::perms::others_exec) != std::filesystem::perms::none) { + return true; + } + } + + return false; +} + +std::string find_executable(const std::vector<std::string>& list) { + std::vector<std::string> paths {Reichwein::Stringhelper::split(env_value("PATH"), ":")}; + + for (const auto& i: list) { + for (const auto& j: paths) { + fs::path path{j + "/" + i}; + if (fs::exists(path) && (fs::status(path).permissions() & std::filesystem::perms::others_exec) != std::filesystem::perms::none) { + return i; + } + } + } + + return {}; +} |