diff options
author | Chris Johns <chrisj@rtems.org> | 2015-03-29 18:06:00 +1100 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2015-03-29 18:06:00 +1100 |
commit | b24951645db3105213ab3f9ce6ae52c84425a4fa (patch) | |
tree | 6fb77c4c7f994b5688ad95cf406a068f805222a1 | |
parent | trace-linker: Update comments. (diff) | |
download | rtems-tools-b24951645db3105213ab3f9ce6ae52c84425a4fa.tar.bz2 |
rtemstoolkit: Add support to return the system path split as paths.
Seacch the path for the program name if not found and set it as
an absolute path. This allow the prefix to be found.
-rw-r--r-- | linkers/rtems-tld.cpp | 2 | ||||
-rw-r--r-- | rtemstoolkit/rld-path.cpp | 18 | ||||
-rw-r--r-- | rtemstoolkit/rld-path.h | 6 | ||||
-rw-r--r-- | rtemstoolkit/rld.cpp | 22 |
4 files changed, 45 insertions, 3 deletions
diff --git a/linkers/rtems-tld.cpp b/linkers/rtems-tld.cpp index 0a25ca8..714c9ee 100644 --- a/linkers/rtems-tld.cpp +++ b/linkers/rtems-tld.cpp @@ -1497,7 +1497,7 @@ namespace rld const std::string& trace, const std::string& path) { - std::string sp = get_prefix (); + std::string sp = rld::get_prefix (); rld::path::path_join (sp, "share", sp); rld::path::path_join (sp, "rtems", sp); diff --git a/rtemstoolkit/rld-path.cpp b/rtemstoolkit/rld-path.cpp index 333c1c2..c848676 100644 --- a/rtemstoolkit/rld-path.cpp +++ b/rtemstoolkit/rld-path.cpp @@ -214,5 +214,23 @@ namespace rld throw rld::error ("Not found", "unlinking: " + path); } } + + void + get_system_path (paths& paths) + { + const char* path = ::getenv ("PATH"); + strings ps; + rld::split (ps, path, RLD_PATHSTR_SEPARATOR); + if (ps.size ()) + { + for (strings::iterator psi = ps.begin (); + psi != ps.end (); + ++psi) + { + if (check_directory (*psi)) + paths.push_back (*psi); + } + } + } } } diff --git a/rtemstoolkit/rld-path.h b/rtemstoolkit/rld-path.h index d73c59b..80921a1 100644 --- a/rtemstoolkit/rld-path.h +++ b/rtemstoolkit/rld-path.h @@ -144,6 +144,12 @@ namespace rld */ void unlink (const std::string& path, bool not_present_error = false); + /** + * Return the system path as a set of strings. + * + * @param paths The split path paths. + */ + void get_system_path (paths& paths); } } diff --git a/rtemstoolkit/rld.cpp b/rtemstoolkit/rld.cpp index c3368f9..b3e6fdc 100644 --- a/rtemstoolkit/rld.cpp +++ b/rtemstoolkit/rld.cpp @@ -235,7 +235,25 @@ namespace rld void set_progname (const std::string& progname_) { - progname = rld::path::path_abs (progname_); + if (rld::path::check_file (progname_)) + progname = rld::path::path_abs (progname_); + else + { + rld::path::paths paths; + rld::path::get_system_path (paths); + for (rld::path::paths::const_iterator path = paths.begin (); + path != paths.end (); + ++path) + { + std::string pp; + rld::path::path_join (*path, progname_, pp); + if (rld::path::check_file (pp)) + { + progname = rld::path::path_abs (pp); + break; + } + } + } } const std::string @@ -262,7 +280,7 @@ namespace rld std::string pp = get_program_path (); if (rld::path::basename (pp) == "bin") return rld::path::dirname (pp); - return ""; + return pp; } void |