From 6ee163875c5334647d09369f361f207f6a97fc49 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 10 Aug 2013 00:50:57 +0000 Subject: Check for $PWD in llvm::sys::current_path. Some users (clang, libTooling) require this. After this patch we can remove the calls to getenv("PWD") from clang. llvm-svn: 188125 --- llvm/lib/Support/Unix/Path.inc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/Support/Unix') diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 4dcfa094a7b..f6a137e7a0b 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -298,6 +298,18 @@ UniqueID file_status::getUniqueID() const { } error_code current_path(SmallVectorImpl &result) { + result.clear(); + + const char *pwd = ::getenv("PWD"); + llvm::sys::fs::file_status PWDStatus, DotStatus; + if (pwd && llvm::sys::path::is_absolute(pwd) && + !llvm::sys::fs::status(pwd, PWDStatus) && + !llvm::sys::fs::status(".", DotStatus) && + PWDStatus.getUniqueID() == DotStatus.getUniqueID()) { + result.append(pwd, pwd + strlen(pwd)); + return error_code::success(); + } + #ifdef MAXPATHLEN result.reserve(MAXPATHLEN); #else -- cgit v1.2.3