From: Chris Lattner Date: Wed, 27 Feb 2008 06:17:10 +0000 (+0000) Subject: Add path separator support, patch by Sam Bishop. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e1b332a30459a726e882a4f484a9a31f2cea9e29;p=oota-llvm.git Add path separator support, patch by Sam Bishop. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47662 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h index db1de770fc2..ee860e8cf91 100644 --- a/include/llvm/System/Path.h +++ b/include/llvm/System/Path.h @@ -662,6 +662,10 @@ namespace sys { /// @returns true if an error occurs, false otherwise /// @brief Copy one file to another. bool CopyFile(const Path& Dest, const Path& Src, std::string* ErrMsg); + + /// This is the OS-specific path separator: a colon on Unix or a semicolon + /// on Windows. + extern const char PathSeparator; } std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath); diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp index 11035cfee7a..8a1de75e478 100644 --- a/lib/System/Path.cpp +++ b/lib/System/Path.cpp @@ -177,6 +177,25 @@ Path::getSuffix() const { return path.substr(path.rfind('.') + 1); } +static void getPathList(const char*path, std::vector& Paths) { + const char* at = path; + const char* delim = strchr(at, PathSeparator); + Path tmpPath; + while (delim != 0) { + std::string tmp(at, size_t(delim-at)); + if (tmpPath.set(tmp)) + if (tmpPath.canRead()) + Paths.push_back(tmpPath); + at = delim + 1; + delim = strchr(at, PathSeparator); + } + + if (*at != 0) + if (tmpPath.set(std::string(at))) + if (tmpPath.canRead()) + Paths.push_back(tmpPath); +} + // Include the truly platform-specific parts of this class. #if defined(LLVM_ON_UNIX) #include "Unix/Path.inc" diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 2dde37cdaee..c8bdd088c32 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -63,6 +63,8 @@ inline bool lastIsSlash(const std::string& path) { namespace llvm { using namespace sys; +extern const char sys::PathSeparator = ':'; + bool Path::isValid() const { // Check some obvious things @@ -183,25 +185,6 @@ Path::GetTemporaryDirectory(std::string* ErrMsg ) { #endif } -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.set(tmp)) - if (tmpPath.canRead()) - Paths.push_back(tmpPath); - at = delim + 1; - delim = strchr(at, ':'); - } - if (*at != 0) - if (tmpPath.set(std::string(at))) - if (tmpPath.canRead()) - Paths.push_back(tmpPath); - -} - void Path::GetSystemLibraryPaths(std::vector& Paths) { #ifdef LTDL_SHLIBPATH_VAR diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index ff5cc0a840f..ee3f622ed32 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -45,6 +45,8 @@ static void FlipBackSlashes(std::string& s) { namespace llvm { namespace sys { +extern const char sys::PathSeparator = ';'; + bool Path::isValid() const { if (path.empty()) @@ -164,25 +166,6 @@ Path::GetRootDirectory() { return result; } -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.set(tmp)) - if (tmpPath.canRead()) - Paths.push_back(tmpPath); - at = delim + 1; - delim = strchr(at, ';'); - } - - if (*at != 0) - if (tmpPath.set(std::string(at))) - if (tmpPath.canRead()) - Paths.push_back(tmpPath); -} - void Path::GetSystemLibraryPaths(std::vector& Paths) { Paths.push_back(sys::Path("C:/WINDOWS/SYSTEM32"));