X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=lib%2FSupport%2FPath.cpp;h=4952f59fc24dd62db383ce328d341f8ec1ee611f;hb=8cda80ad2486782d40ac51cb07dfc630fee47639;hp=e5150bcbb7ef510bccdf5ee5c6eebaf27f8ff593;hpb=5db595015179e5e2db1afb5d8c9c55c0413217ca;p=oota-llvm.git diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index e5150bcbb7e..4952f59fc24 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -671,6 +671,41 @@ StringRef remove_leading_dotslash(StringRef Path) { return Path; } +static SmallString<256> remove_dots(StringRef path, bool remove_dot_dot) { + SmallVector components; + + // Skip the root path, then look for traversal in the components. + StringRef rel = path::relative_path(path); + for (StringRef C : llvm::make_range(path::begin(rel), path::end(rel))) { + if (C == ".") + continue; + if (remove_dot_dot) { + if (C == "..") { + if (!components.empty()) + components.pop_back(); + continue; + } + } + components.push_back(C); + } + + SmallString<256> buffer = path::root_path(path); + for (StringRef C : components) + path::append(buffer, C); + return buffer; +} + +bool remove_dots(SmallVectorImpl &path, bool remove_dot_dot) { + StringRef p(path.data(), path.size()); + + SmallString<256> result = remove_dots(p, remove_dot_dot); + if (result == path) + return false; + + path.swap(result); + return true; +} + } // end namespace path namespace fs { @@ -1094,3 +1129,20 @@ std::error_code directory_entry::status(file_status &result) const { #if defined(LLVM_ON_WIN32) #include "Windows/Path.inc" #endif + +namespace llvm { +namespace sys { +namespace path { + +bool user_cache_directory(SmallVectorImpl &Result, const Twine &Path1, + const Twine &Path2, const Twine &Path3) { + if (getUserCacheDir(Result)) { + append(Result, Path1, Path2, Path3); + return true; + } + return false; +} + +} // end namespace path +} // end namsspace sys +} // end namespace llvm