summaryrefslogtreecommitdiffhomepage
path: root/file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'file.cpp')
-rw-r--r--file.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/file.cpp b/file.cpp
index da00dff..3149f63 100644
--- a/file.cpp
+++ b/file.cpp
@@ -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 {};
+}