diff options
| author | _ov4 <ov4@ov4.org> | 2026-08-31 08:23:26 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-08-31 08:23:26 +0000 |
| commit | 097165066c0f83c57e4f4cce02225c601deb2f02 (patch) | |
| tree | 9f3b007eaf136a69b83a2bd7c716b5b5f2c46814 /src/path.cc | |
| parent | 0e460c391c093f1eb074d3192c60d37fa425d48d (diff) | |
path
Diffstat (limited to 'src/path.cc')
| -rw-r--r-- | src/path.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/path.cc b/src/path.cc new file mode 100644 index 0000000..519fd20 --- /dev/null +++ b/src/path.cc @@ -0,0 +1,42 @@ +#include "path.h" + +namespace ov4 +{ + +using namespace std; + +string find_cmd(char* s) +{ + string tmp = s; + return find_cmd(tmp); +} + +string find_cmd(string s) +{ + if (s.size() == 0) return "/"; + if (s[0] == '/') return s; + + string path = getenv("PATH"); + size_t i = 0, j = 0, l = path.size(); + while (true) + { + for (; j < l; j++) + if (path[j] == ':') + break; + + string cmd = path.substr(i, j-i) + '/' +s; + cout << cmd << endl; + if (access(cmd.c_str(), F_OK) == 0) + return cmd; + + if (j == l) + return "/"; + + j++; + i=j; + + } +} + + +} |
