[llvm-commits] CVS: llvm/lib/System/Unix/Path.cpp
Reid Spencer
reid at x10sys.com
Mon Sep 13 17:16:50 PDT 2004
Changes in directory llvm/lib/System/Unix:
Path.cpp updated: 1.5 -> 1.6
---
Log message:
Implement the GetLibraryPath function.
---
Diffs of the changes: (+45 -0)
Index: llvm/lib/System/Unix/Path.cpp
diff -u llvm/lib/System/Unix/Path.cpp:1.5 llvm/lib/System/Unix/Path.cpp:1.6
--- llvm/lib/System/Unix/Path.cpp:1.5 Fri Sep 10 23:55:08 2004
+++ llvm/lib/System/Unix/Path.cpp Mon Sep 13 19:16:39 2004
@@ -44,6 +44,51 @@
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/");
More information about the llvm-commits
mailing list