diff options
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/Unix/Path.inc | 11 | ||||
-rw-r--r-- | lib/Support/Windows/Path.inc | 10 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 06b18be..57f02be 100644 --- a/lib/Support/Unix/Path.inc +++ b/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/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index bb1f77a..4a6e563 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -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* 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) { |