adds the elements of the env variable path to the arg passed in
| 606 | |
| 607 | // adds the elements of the env variable path to the arg passed in |
| 608 | void SystemTools::GetPath(std::vector<std::string>& path, char const* env) |
| 609 | { |
| 610 | size_t const old_size = path.size(); |
| 611 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 612 | char const pathSep = ';'; |
| 613 | #else |
| 614 | char const pathSep = ':'; |
| 615 | #endif |
| 616 | if (!env) { |
| 617 | env = "PATH"; |
| 618 | } |
| 619 | std::string pathEnv; |
| 620 | if (!SystemTools::GetEnv(env, pathEnv)) { |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | // A hack to make the below algorithm work. |
| 625 | if (!pathEnv.empty() && pathEnv.back() != pathSep) { |
| 626 | pathEnv += pathSep; |
| 627 | } |
| 628 | std::string::size_type start = 0; |
| 629 | bool done = false; |
| 630 | while (!done) { |
| 631 | std::string::size_type endpos = pathEnv.find(pathSep, start); |
| 632 | if (endpos != std::string::npos) { |
| 633 | path.push_back(pathEnv.substr(start, endpos - start)); |
| 634 | start = endpos + 1; |
| 635 | } else { |
| 636 | done = true; |
| 637 | } |
| 638 | } |
| 639 | for (auto i = path.begin() + old_size; i != path.end(); ++i) { |
| 640 | SystemTools::ConvertToUnixSlashes(*i); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | #if defined(_WIN32) |
| 645 | char const* SystemToolsStatic::GetEnvBuffered(char const* key) |