From 6c4b7bded1188903ac6a4deeddbfad8c7d425ddf Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Mon, 13 Dec 2004 03:03:42 +0000 Subject: [PATCH] Implement new functions per new interface git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18866 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/Win32/Path.cpp | 103 ++++++++++++++++++-------------------- lib/System/Win32/Path.inc | 103 ++++++++++++++++++-------------------- 2 files changed, 96 insertions(+), 110 deletions(-) diff --git a/lib/System/Win32/Path.cpp b/lib/System/Win32/Path.cpp index 944aea101fb..cb4594194a8 100644 --- a/lib/System/Win32/Path.cpp +++ b/lib/System/Win32/Path.cpp @@ -123,67 +123,60 @@ Path::GetDLLSuffix() { return "dll"; } -static inline bool IsLibrary(Path& path, const std::string& basename) { - if (path.appendFile(std::string("lib") + basename)) { - if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("a") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("o") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable()) - return true; - } else if (path.elideFile() && path.appendFile(basename)) { - if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("a") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("o") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable()) - return true; +static void getPathList(const char*path, std::vector& Paths) { + const char* at = path; + const char* delim = strchr(at, ';'); + Path tmpPath; + while( delim != 0 ) { + std::string tmp(at, size_t(delim-at)); + if (tmpPath.setDirectory(tmp)) + if (tmpPath.readable()) + Paths.push_back(tmpPath); + at = delim + 1; + delim = strchr(at, ';'); } - path.clear(); - return false; -} - -Path -Path::GetLibraryPath(const std::string& basename, - const std::vector& LibPaths) { - Path result; - - // Try the paths provided - for (std::vector::const_iterator I = LibPaths.begin(), - E = LibPaths.end(); I != E; ++I ) { - if (result.setDirectory(*I) && IsLibrary(result,basename)) - return result; - } - - // Try the LLVM lib directory in the LLVM install area - //if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename)) - // return result; + if (*at != 0) + if (tmpPath.setDirectory(std::string(at))) + if (tmpPath.readable()) + Paths.push_back(tmpPath); - // Try /usr/lib - if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename)) - return result; - - // Try /lib - if (result.setDirectory("/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/"); +void +Path::GetSystemLibraryPaths(std::vector& Paths) { +#ifdef LTDL_SHLIBPATH_VAR + char* env_var = getenv(LTDL_SHLIBPATH_VAR); + if (env_var != 0) { + getPathList(env_var,Paths); + } +#endif + // FIXME: Should this look at LD_LIBRARY_PATH too? + Paths.push_back(sys::Path("C:\\WINDOWS\\SYSTEM32\\")); + Paths.push_back(sys::Path("C:\\WINDOWS\\")); } -Path -Path::GetSystemLibraryPath2() { - return Path("/usr/lib/"); +void +Path::GetBytecodeLibraryPaths(std::vector& Paths) { + char * env_var = getenv("LLVM_LIB_SEARCH_PATH"); + if (env_var != 0) { + getPathList(env_var,Paths); + } +#ifdef LLVMGCCDIR + { + Path tmpPath(std::string(LLVMGCCDIR) + "bytecode-libs/"); + if (tmpPath.readable()) + Paths.push_back(tmpPath); + } +#endif +#ifdef LLVM_LIBDIR + { + Path tmpPath; + if (tmpPath.setDirectory(LLVM_LIBDIR)) + if (tmpPath.readable()) + Paths.push_back(tmpPath); + } +#endif + GetSystemLibraryPaths(Paths); } Path diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index 944aea101fb..cb4594194a8 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -123,67 +123,60 @@ Path::GetDLLSuffix() { return "dll"; } -static inline bool IsLibrary(Path& path, const std::string& basename) { - if (path.appendFile(std::string("lib") + basename)) { - if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("a") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("o") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable()) - return true; - } else if (path.elideFile() && path.appendFile(basename)) { - if (path.appendSuffix(Path::GetDLLSuffix()) && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("a") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("o") && path.readable()) - return true; - else if (path.elideSuffix() && path.appendSuffix("bc") && path.readable()) - return true; +static void getPathList(const char*path, std::vector& Paths) { + const char* at = path; + const char* delim = strchr(at, ';'); + Path tmpPath; + while( delim != 0 ) { + std::string tmp(at, size_t(delim-at)); + if (tmpPath.setDirectory(tmp)) + if (tmpPath.readable()) + Paths.push_back(tmpPath); + at = delim + 1; + delim = strchr(at, ';'); } - path.clear(); - return false; -} - -Path -Path::GetLibraryPath(const std::string& basename, - const std::vector& LibPaths) { - Path result; - - // Try the paths provided - for (std::vector::const_iterator I = LibPaths.begin(), - E = LibPaths.end(); I != E; ++I ) { - if (result.setDirectory(*I) && IsLibrary(result,basename)) - return result; - } - - // Try the LLVM lib directory in the LLVM install area - //if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename)) - // return result; + if (*at != 0) + if (tmpPath.setDirectory(std::string(at))) + if (tmpPath.readable()) + Paths.push_back(tmpPath); - // Try /usr/lib - if (result.setDirectory("/usr/lib/") && IsLibrary(result,basename)) - return result; - - // Try /lib - if (result.setDirectory("/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/"); +void +Path::GetSystemLibraryPaths(std::vector& Paths) { +#ifdef LTDL_SHLIBPATH_VAR + char* env_var = getenv(LTDL_SHLIBPATH_VAR); + if (env_var != 0) { + getPathList(env_var,Paths); + } +#endif + // FIXME: Should this look at LD_LIBRARY_PATH too? + Paths.push_back(sys::Path("C:\\WINDOWS\\SYSTEM32\\")); + Paths.push_back(sys::Path("C:\\WINDOWS\\")); } -Path -Path::GetSystemLibraryPath2() { - return Path("/usr/lib/"); +void +Path::GetBytecodeLibraryPaths(std::vector& Paths) { + char * env_var = getenv("LLVM_LIB_SEARCH_PATH"); + if (env_var != 0) { + getPathList(env_var,Paths); + } +#ifdef LLVMGCCDIR + { + Path tmpPath(std::string(LLVMGCCDIR) + "bytecode-libs/"); + if (tmpPath.readable()) + Paths.push_back(tmpPath); + } +#endif +#ifdef LLVM_LIBDIR + { + Path tmpPath; + if (tmpPath.setDirectory(LLVM_LIBDIR)) + if (tmpPath.readable()) + Paths.push_back(tmpPath); + } +#endif + GetSystemLibraryPaths(Paths); } Path -- 2.34.1