From f2eb782080a74a7d789dea154e17e18cf5121af4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 28 Dec 2025 21:48:09 +0100 Subject: WIP --- src/util.cc | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/util.cc') diff --git a/src/util.cc b/src/util.cc index 7ca9c11..ac4da8e 100644 --- a/src/util.cc +++ b/src/util.cc @@ -80,7 +80,7 @@ namespace { bool isClean(char c) { - return c != '.' && c != '/'; + return c != '.' && c != '/' && c != '\\'; } } @@ -189,15 +189,36 @@ std::string locate(const std::string& prog, } } + if(std::filesystem::exists(program + ".exe")) + { + if(check_executable(program + ".exe")) + { + return program + ".exe"; + } + } + for(const auto& path_str : paths) { std::filesystem::path path(path_str); - auto prog_path = path / program; - if(std::filesystem::exists(prog_path)) { - if(check_executable(prog_path)) + auto prog_path = path / program; + if(std::filesystem::exists(prog_path)) + { + if(check_executable(prog_path)) + { + return prog_path.string(); + } + } + } + + { + auto prog_path = path / (program + ".exe"); + if(std::filesystem::exists(prog_path)) { - return prog_path.string(); + if(check_executable(prog_path)) + { + return prog_path.string(); + } } } } @@ -299,6 +320,17 @@ std::vector argsplit(std::string_view str) bool get_env(std::string_view name, std::string& value) { +#if defined(_WIN32) + std::size_t size{}; + getenv_s(&size, nullptr, 0, name.data()); + if(size == 0) + { + return false; + } + value.resize(size); + getenv_s(&size, value.data(), size, name.data()); + return true; +#else auto var = getenv(name.data()); if(var) { @@ -306,4 +338,5 @@ bool get_env(std::string_view name, std::string& value) return true; } return false; +#endif } -- cgit v1.2.3