diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2004-12-13 03:00:51 +0000 | 
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2004-12-13 03:00:51 +0000 | 
| commit | 9b155dc4c0e18673af22ef0a421071b29687d3f4 (patch) | |
| tree | 475453f2efdca8a3456f318237fe9afd91008894 /llvm/lib/System | |
| parent | 66b818286620e73faad98bd35682ed9907258370 (diff) | |
| download | bcm5719-llvm-9b155dc4c0e18673af22ef0a421071b29687d3f4.tar.gz bcm5719-llvm-9b155dc4c0e18673af22ef0a421071b29687d3f4.zip  | |
For PR351: \
* Remove IsLibrary and GetLibraryPath, replaced by FindLibrary in ../Path.cpp \
* Implement GetSystemLibraryPaths and GetBytecodeLibraryPaths, instead of the \
  GetSystemLibraryPath1 and GetSystemLibraryPath2 methods
llvm-svn: 18862
Diffstat (limited to 'llvm/lib/System')
| -rw-r--r-- | llvm/lib/System/Unix/Path.cpp | 121 | 
1 files changed, 54 insertions, 67 deletions
diff --git a/llvm/lib/System/Unix/Path.cpp b/llvm/lib/System/Unix/Path.cpp index d3e4d96a83e..63184f6c1c5 100644 --- a/llvm/lib/System/Unix/Path.cpp +++ b/llvm/lib/System/Unix/Path.cpp @@ -46,67 +46,61 @@ Path::GetRootDirectory() {    return result;  } -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<sys::Path>& 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<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.setDirectory(*I) && IsLibrary(result,basename)) -      return result; +  if (*at != 0) +    if (tmpPath.setDirectory(std::string(at))) +      if (tmpPath.readable()) +        Paths.push_back(tmpPath); + +} +void  +Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) { +#ifdef LTDL_SHLIBPATH_VAR +  char* env_var = getenv(LTDL_SHLIBPATH_VAR); +  if (env_var != 0) { +    getPathList(env_var,Paths);    } - -  // Try the LLVM lib directory in the LLVM install area -  if (result.setDirectory(LLVM_LIBDIR) && IsLibrary(result,basename)) -    return result; - -  // 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/"); +#endif +  // FIXME: Should this look at LD_LIBRARY_PATH too? +  Paths.push_back(sys::Path("/usr/local/lib/")); +  Paths.push_back(sys::Path("/usr/X11R6/lib/")); +  Paths.push_back(sys::Path("/usr/lib/")); +  Paths.push_back(sys::Path("/lib/"));  } -Path  -Path::GetSystemLibraryPath2() { -  return Path("/usr/lib/"); +void +Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& 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  @@ -162,9 +156,10 @@ bool Path::hasMagicNumber(const std::string &Magic) const {    int fd = ::open(path.c_str(),O_RDONLY);    if (fd < 0)      return false; -  if (0 != ::read(fd, buf, len)) -    return false; +  size_t read_len = ::read(fd, buf, len);    close(fd); +  if (len != read_len) +    return false;    buf[len] = '\0';    return Magic == buf;  } @@ -204,14 +199,6 @@ Path::isBytecodeFile() const {  }  bool -Path::isArchive() const { -  if (readable()) { -    return hasMagicNumber("!<arch>\012"); -  } -  return false; -} - -bool  Path::exists() const {    return 0 == access(path.c_str(), F_OK );  }  | 

