[llvm] r184009 - Add GetCurrentDirectory back.

Rafael Espindola rafael.espindola at gmail.com
Fri Jun 14 14:41:33 PDT 2013


Author: rafael
Date: Fri Jun 14 16:41:33 2013
New Revision: 184009

URL: http://llvm.org/viewvc/llvm-project?rev=184009&view=rev
Log:
Add GetCurrentDirectory back.

It looks like clang-tools-extra/unittests/cpp11-migrate/TransformTest.cpp
depends on the behaviour of the old one on Windows. Maybe a difference
between GetCurrentDirectoryA and GetCurrentDirectoryW?

Modified:
    llvm/trunk/include/llvm/Support/PathV1.h
    llvm/trunk/lib/Support/Unix/Path.inc
    llvm/trunk/lib/Support/Windows/Path.inc

Modified: llvm/trunk/include/llvm/Support/PathV1.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PathV1.h?rev=184009&r1=184008&r2=184009&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PathV1.h (original)
+++ llvm/trunk/include/llvm/Support/PathV1.h Fri Jun 14 16:41:33 2013
@@ -102,6 +102,11 @@ namespace sys {
       /// directory.
       static Path GetTemporaryDirectory(std::string* ErrMsg = 0);
 
+      /// Construct a path to the current directory for the current process.
+      /// @returns The current working directory.
+      /// @brief Returns the current working directory.
+      static Path GetCurrentDirectory();
+
       /// Return the suffix commonly used on file names that contain an
       /// executable.
       /// @returns The executable file suffix for the current platform.

Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=184009&r1=184008&r2=184009&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Fri Jun 14 16:41:33 2013
@@ -185,6 +185,17 @@ Path::GetTemporaryDirectory(std::string
 #endif
 }
 
+Path
+Path::GetCurrentDirectory() {
+  char pathname[MAXPATHLEN];
+  if (!getcwd(pathname, MAXPATHLEN)) {
+    assert(false && "Could not query current working directory.");
+    return Path();
+  }
+
+  return Path(pathname);
+}
+
 #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
     defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \
     defined(__linux__) || defined(__CYGWIN__)

Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=184009&r1=184008&r2=184009&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Fri Jun 14 16:41:33 2013
@@ -20,6 +20,9 @@
 #include <cstdio>
 #include <malloc.h>
 
+// We need to undo a macro defined in Windows.h, otherwise we won't compile:
+#undef GetCurrentDirectory
+
 // Windows happily accepts either forward or backward slashes, though any path
 // returned by a Win32 API will have backward slashes.  As LLVM code basically
 // assumes forward slashes are used, backward slashs are converted where they
@@ -196,6 +199,13 @@ Path::GetTemporaryDirectory(std::string*
   return *TempDirectory;
 }
 
+Path
+Path::GetCurrentDirectory() {
+  char pathname[MAX_PATH];
+  ::GetCurrentDirectoryA(MAX_PATH,pathname);
+  return Path(pathname);
+}
+
 /// GetMainExecutable - Return the path to the main executable, given the
 /// value of argv[0] from program startup.
 Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {





More information about the llvm-commits mailing list