diff options
author | Sterling Augustine <saugustine@google.com> | 2011-11-17 17:46:54 +0000 |
---|---|---|
committer | Sterling Augustine <saugustine@google.com> | 2011-11-17 17:46:54 +0000 |
commit | 628f39beca35cfdf725fdb4f855272c1166ad656 (patch) | |
tree | 1b820aae7730c0b44b8c10f05c98b58dd9650afe /gold/dirsearch.cc | |
parent | a7bbf4e9b9ed14909afef85db4ffc91a6f4cb50a (diff) | |
download | gdb-628f39beca35cfdf725fdb4f855272c1166ad656.zip gdb-628f39beca35cfdf725fdb4f855272c1166ad656.tar.gz gdb-628f39beca35cfdf725fdb4f855272c1166ad656.tar.bz2 |
2011-11-17 Sterling Augustine <saugustine@google.com>
* script.cc (script_include_directive): Implement.
(read_script_file): New local variables name and search_path. Update
comment. Call IS_ABSOLUTE_PATH and Dirsearch::find_file_in_dir_list.
* dirsearch.h (Dirsearch::find_file_in_dir_list): Declare new method.
* dirsearch.cc (Dirsearch::find_file_in_dir_list): Implement it.
Diffstat (limited to 'gold/dirsearch.cc')
-rw-r--r-- | gold/dirsearch.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gold/dirsearch.cc b/gold/dirsearch.cc index 1ae2055..a6114a4 100644 --- a/gold/dirsearch.cc +++ b/gold/dirsearch.cc @@ -25,6 +25,7 @@ #include <cerrno> #include <cstring> #include <sys/types.h> +#include <sys/stat.h> #include <dirent.h> #include "debug.h" @@ -277,4 +278,28 @@ Dirsearch::find(const std::vector<std::string>& names, return std::string(); } +// Search for a file in a directory list. This is a low-level function and +// therefore can be used before options and parameters are set. + +std::string +Dirsearch::find_file_in_dir_list(const std::string& name, + const General_options::Dir_list& directories, + const std::string& extra_search_dir) +{ + struct stat buf; + std::string extra_name = extra_search_dir + '/' + name; + + if (stat(extra_name.c_str(), &buf) == 0) + return extra_name; + for (General_options::Dir_list::const_iterator dir = directories.begin(); + dir != directories.end(); + ++dir) + { + std::string full_name = dir->name() + '/' + name; + if (stat(full_name.c_str(), &buf) == 0) + return full_name; + } + return name; +} + } // End namespace gold. |