Add sys::Path::makeAbsolute().
authorDaniel Dunbar <daniel@zuster.org>
Thu, 9 Apr 2009 00:33:08 +0000 (00:33 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 9 Apr 2009 00:33:08 +0000 (00:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68663 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Path.h
lib/System/Path.cpp

index d28e11e545688089091d8c2ffdd8d4cb7c0d0592..de2f173ae41751f4b6a6b6f600169cf2b92d219a 100644 (file)
@@ -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
     /// @{
index c5a4b0676ff743d1053643da0a45563868fdd1db..4c965db7223383e085954dcd14df76c27e04cedc 100644 (file)
@@ -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<Path>& Paths) {
   const char* at = path;
   const char* delim = strchr(at, PathSeparator);