From cd6c3ea1c3ca853fc38da4fa5fd62545c31aa92d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 3 Apr 2025 07:56:04 +0200 Subject: Refactor getenv usage. --- src/util.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/util.cc') diff --git a/src/util.cc b/src/util.cc index 3517e0b..a4abd23 100644 --- a/src/util.cc +++ b/src/util.cc @@ -8,6 +8,7 @@ #include #include #include +#include std::string to_lower(std::string str) { @@ -117,8 +118,18 @@ std::string esc(const std::string& in) return out; } -std::vector get_paths(const std::string& path_env) +std::vector get_paths(const std::string& path_env_) { + std::string path_env; + if(!path_env_.empty()) + { + path_env = path_env_; + } + else + { + get_env("PATH", path_env); + } + std::vector paths; #ifdef _WIN32 @@ -285,3 +296,14 @@ std::vector argsplit(const std::string& str) } return tokens; } + +bool get_env(std::string_view name, std::string& value) +{ + auto var = getenv(name.data()); + if(var) + { + value = var; + return true; + } + return false; +} -- cgit v1.2.3