summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Unix/Path.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-09-14 00:16:39 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-09-14 00:16:39 +0000
commitdf05ec7e0dd8a117597bc0b03128f2fb683de8de (patch)
tree306950e31b7ddd89a0c67177b5225203b892c687 /llvm/lib/System/Unix/Path.cpp
parent41c5e9f2fcfa8420c8665b5b58289dbc9d103f90 (diff)
downloadbcm5719-llvm-df05ec7e0dd8a117597bc0b03128f2fb683de8de.tar.gz
bcm5719-llvm-df05ec7e0dd8a117597bc0b03128f2fb683de8de.zip
Implement the GetLibraryPath function.
llvm-svn: 16323
Diffstat (limited to 'llvm/lib/System/Unix/Path.cpp')
-rw-r--r--llvm/lib/System/Unix/Path.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/llvm/lib/System/Unix/Path.cpp b/llvm/lib/System/Unix/Path.cpp
index 23b938b9019..329bf37e387 100644
--- a/llvm/lib/System/Unix/Path.cpp
+++ b/llvm/lib/System/Unix/Path.cpp
@@ -44,6 +44,51 @@ Path::GetRootDirectory() {
return result;
}
+static inline bool IsLibrary(Path& path, const std::string& basename) {
+ if (path.append_file(std::string("lib") + basename)) {
+ if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ return true;
+ else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ return true;
+ else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ return true;
+ } else if (path.elide_file() && path.append_file(basename)) {
+ if (path.append_suffix(Path::GetDLLSuffix()) && path.readable())
+ return true;
+ else if (path.elide_suffix() && path.append_suffix("a") && path.readable())
+ return true;
+ else if (path.elide_suffix() && path.append_suffix("o") && path.readable())
+ return true;
+ }
+ path.clear();
+ return false;
+}
+
+Path
+Path::GetLibraryPath(const std::string& basename,
+ const std::vector<std::string>& LibPaths) {
+ Path result;
+
+ // Try the paths provided
+ for (std::vector<std::string>::const_iterator I = LibPaths.begin(),
+ E = LibPaths.end(); I != E; ++I ) {
+ if (result.set_directory(*I) && IsLibrary(result,basename))
+ return result;
+ }
+
+ // Try /usr/lib
+ if (result.set_directory("/usr/lib/") && IsLibrary(result,basename))
+ return result;
+
+ // Try /lib
+ if (result.set_directory("/lib/") && IsLibrary(result,basename))
+ return result;
+
+ // Can't find it, give up and return invalid path.
+ result.clear();
+ return result;
+}
+
Path
Path::GetSystemLibraryPath1() {
return Path("/lib/");
OpenPOWER on IntegriCloud