Commit 730e8c5d authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Adding search_env_path in radixcore/system.

parent acb3f12d
Pipeline #12768 passed with stages
in 8 minutes and 56 seconds
......@@ -366,6 +366,33 @@ bool remove_file(const std::string &path)
{
if (dir_exists(path)) return false;
return remove(path.c_str()) == 0;
} // remove_file
}
std::string search_env_path(const std::string &filename)
{
std::string path_env = env("PATH");
std::vector<std::string> list = split_string(":", path_env);
if (list.size() == 1) // we didn't split anything
{
// guess it was ':' separator, try ';'
list = split_string(";", path_env);
}
for (size_t i = 0; i < list.size(); ++i)
{
std::string item = list[i];
item = item + separator_char();
radix_line("Searching " << item << " for " << filename);
std::string path = item + filename;
if (file_exists(path))
{
radix_line("Found " << path);
return path;
}
}
radix_line("Did not find " << filename << " on the PATH");
return std::string();
}
// remove_file
} // namespace radix
......@@ -192,6 +192,13 @@ RADIX_PUBLIC bool remove_dir(const std::string &path);
*/
RADIX_PUBLIC bool remove_file(const std::string &path);
/**
* @brief search_env_path Search the environment variable PATH for the filename
* @param filename filename to search for
* @return The PATH prefix if the filename is found to exist or empty.
*/
RADIX_PUBLIC std::string search_env_path(const std::string &filename);
} // namespace radix
#endif /** RADIX_RADIXCORE_SYSTEM_HH_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment