mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Add a function for splitting search paths
This commit is contained in:
@@ -42,6 +42,30 @@ bool pid_running(pid_t pid) {
|
||||
return !err || err.value() == EACCES;
|
||||
}
|
||||
|
||||
std::vector<ghc::filesystem::path> split_path(
|
||||
const std::string_view& path_env) {
|
||||
// C++ has these great split range adapters. That are completely usless.
|
||||
std::vector<fs::path> search_path;
|
||||
|
||||
size_t segment_begin = 0;
|
||||
while (segment_begin != path_env.size()) {
|
||||
const size_t segment_end = path_env.find(':', segment_begin);
|
||||
if (segment_end == std::string_view::npos) {
|
||||
search_path.push_back(path_env.substr(
|
||||
segment_begin, path_env.size() - segment_begin));
|
||||
break;
|
||||
} else {
|
||||
search_path.push_back(
|
||||
path_env.substr(segment_begin, segment_end - segment_begin));
|
||||
|
||||
// Restart after the colon
|
||||
segment_begin = segment_end + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return search_path;
|
||||
}
|
||||
|
||||
ProcessEnvironment::ProcessEnvironment(char** initial_env) {
|
||||
// We'll need to read all strings from `initial_env`. They _should_ all be
|
||||
// zero-terminated strings, with a null pointer to indicate the end of the
|
||||
|
||||
@@ -41,6 +41,12 @@
|
||||
*/
|
||||
bool pid_running(pid_t pid);
|
||||
|
||||
/**
|
||||
* Split a `PATH`-like environment variable on colons. These environment
|
||||
* variables don't support escaping, which makes this a lot simpler.
|
||||
*/
|
||||
std::vector<ghc::filesystem::path> split_path(const std::string_view& path_env);
|
||||
|
||||
/**
|
||||
* Helper to create an `environ`-like environment object for passing to the
|
||||
* `exec*e()` family of functions.
|
||||
|
||||
Reference in New Issue
Block a user