From 158d537c5a0ae834a2899121d1da693af8f78859 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 14 Jun 2013 21:41:33 +0000 Subject: [PATCH] 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? llvm-svn: 184009 --- llvm/include/llvm/Support/PathV1.h | 5 +++++ llvm/lib/Support/Unix/Path.inc | 11 +++++++++++ llvm/lib/Support/Windows/Path.inc | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/llvm/include/llvm/Support/PathV1.h b/llvm/include/llvm/Support/PathV1.h index d3f82bb567e4..eaf255086969 100644 --- a/llvm/include/llvm/Support/PathV1.h +++ b/llvm/include/llvm/Support/PathV1.h @@ -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. diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 06b18bec8b65..57f02be10947 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -185,6 +185,17 @@ Path::GetTemporaryDirectory(std::string *ErrMsg) { #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__) diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index bb1f77ab23cc..4a6e56350b40 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -20,6 +20,9 @@ #include #include +// 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* ErrMsg) { 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) {