From: Daniel Dunbar Date: Thu, 9 Apr 2009 00:33:08 +0000 (+0000) Subject: Add sys::Path::makeAbsolute(). X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6ddf2c1930d896cbe738fab7d07dc977df41918e;p=oota-llvm.git Add sys::Path::makeAbsolute(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68663 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h index d28e11e5456..de2f173ae41 100644 --- a/include/llvm/System/Path.h +++ b/include/llvm/System/Path.h @@ -459,6 +459,10 @@ namespace sys { /// @brief Make the current path name unique in the file system. bool makeUnique( bool reuse_current /*= true*/, std::string* ErrMsg ); + /// The current Path name is made absolute by prepending the + /// current working directory if necessary. + void makeAbsolute(); + /// @} /// @name Disk Mutators /// @{ diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp index c5a4b0676ff..4c965db7223 100644 --- a/lib/System/Path.cpp +++ b/lib/System/Path.cpp @@ -207,6 +207,18 @@ bool Path::hasMagicNumber(const std::string &Magic) const { return false; } +void Path::makeAbsolute() { + if (isAbsolute()) + return; + + Path CWD = Path::GetCurrentDirectory(); + assert(CWD.isAbsolute() && "GetCurrentDirectory returned relative path!"); + + CWD.appendComponent(path); + + path = CWD.toString(); +} + static void getPathList(const char*path, std::vector& Paths) { const char* at = path; const char* delim = strchr(at, PathSeparator);