summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc43
1 files changed, 38 insertions, 5 deletions
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<std::string> 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
}