diff options
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/src/util.cc b/src/util.cc index a4abd23..9bb173f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -15,7 +15,7 @@ std::string to_lower(std::string str) std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { - return std::tolower(c); + return static_cast<char>(std::tolower(c)); }); return str; } @@ -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<std::string> argsplit(const std::string& 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 } |