aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/find_in_path.ccm
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.posix/find_in_path.ccm')
-rw-r--r--nihil.posix/find_in_path.ccm24
1 files changed, 24 insertions, 0 deletions
diff --git a/nihil.posix/find_in_path.ccm b/nihil.posix/find_in_path.ccm
new file mode 100644
index 0000000..4988a12
--- /dev/null
+++ b/nihil.posix/find_in_path.ccm
@@ -0,0 +1,24 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+module;
+
+#include <filesystem>
+#include <optional>
+
+export module nihil.posix:find_in_path;
+
+import nihil.error;
+import :fd;
+
+namespace nihil {
+
+/*
+ * Find an executable in $PATH and return the full path. If $PATH is not set, uses _PATH_DEFPATH.
+ * If the file can't be found or opened, returns std::nullopt.
+ */
+export [[nodiscard]] auto find_in_path(std::filesystem::path const &file)
+ -> std::optional<std::filesystem::path>;
+
+} // namespace nihil