Improve sys::Path::makeAbsolute on Win32.
authorDaniel Dunbar <daniel@zuster.org>
Sun, 12 Jul 2009 20:23:56 +0000 (20:23 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 12 Jul 2009 20:23:56 +0000 (20:23 +0000)
 - Patch by Viktor Kutuzov!

 - Minor tweak by me to add llvm_unreachable calls on FIXMEd error paths.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75424 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/SystemUtils.cpp
lib/System/Path.cpp
lib/System/Unix/Path.inc
lib/System/Win32/Path.inc

index c8c323876bfb25aa34eb64aedee445f4123d1ab8..c86e200fd9514c8f6c8cec74717121ac174e5fbf 100644 (file)
@@ -51,7 +51,7 @@ sys::Path llvm::FindExecutable(const std::string &ExeName,
 
   // Otherwise check the directory that the calling program is in.  We can do
   // this if ProgramPath contains at least one / character, indicating that it
-  // is a relative path to bugpoint itself.
+  // is a relative path to the executable itself.
   Result = ProgramPath;
   Result.eraseComponent();
   if (!Result.isEmpty()) {
index 72bd7ad6f0468c65de9450b5f91dc1d367a46fa3..ce4762e56d84ce1d4ad59aa93f7217b525fc5be3 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "llvm/System/Path.h"
 #include "llvm/Config/config.h"
+#include "llvm/Support/ErrorHandling.h"
 #include <cassert>
 #include <cstring>
 #include <ostream>
@@ -207,18 +208,6 @@ 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);
index 125a0ab209ca1397d693c2e434cc633f80209607..e951fa0355768f36056c5af02d1e5c2bde744b87 100644 (file)
@@ -109,6 +109,19 @@ Path::isAbsolute() const {
     return false;
   return path[0] == '/';
 }
+
+void Path::makeAbsolute() {
+  if (isAbsolute())
+    return;
+
+  Path CWD = Path::GetCurrentDirectory();
+  assert(CWD.isAbsolute() && "GetCurrentDirectory returned relative path!");
+
+  CWD.appendComponent(path);
+
+  path = CWD.toString();
+}
+
 Path
 Path::GetRootDirectory() {
   Path result;
index 683c94bba44eea5a40303ba549a8095c197fb787..dac1d1dafb5d608e6f4c9fe264cb8d292ef627dd 100644 (file)
@@ -125,9 +125,30 @@ Path::isValid() const {
   return true;
 }
 
+void Path::makeAbsolute() {
+  TCHAR  FullPath[MAX_PATH + 1] = {0}; 
+  LPTSTR FilePart = NULL;
+
+  DWORD RetLength = ::GetFullPathNameA(path.c_str(),
+                        sizeof(FullPath)/sizeof(FullPath[0]),
+                        FullPath, &FilePart);
+
+  if (0 == RetLength) {
+    // FIXME: Report the error GetLastError()
+    llvm_unreachable("Unable to make absolute path!");
+  } else if (RetLength > MAX_PATH) {
+    // FIXME: Report too small buffer (needed RetLength bytes).
+    llvm_unreachable("Unable to make absolute path!");
+  } else {
+    path = FullPath;
+  }
+}
+
 bool
 Path::isAbsolute(const char *NameStart, unsigned NameLen) {
   assert(NameStart);
+  // FIXME: This does not handle correctly an absolute path starting from
+  // a drive letter or in UNC format.
   switch (NameLen) {
   case 0:
     return false;
@@ -141,6 +162,8 @@ Path::isAbsolute(const char *NameStart, unsigned NameLen) {
 
 bool 
 Path::isAbsolute() const {
+  // FIXME: This does not handle correctly an absolute path starting from
+  // a drive letter or in UNC format.
   switch (path.length()) {
     case 0:
       return false;