Index: lib/Support/Windows/Path.inc =================================================================== --- lib/Support/Windows/Path.inc +++ lib/Support/Windows/Path.inc @@ -17,6 +17,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/WindowsError.h" #include #include @@ -280,12 +281,26 @@ } std::error_code access(const Twine &Path, AccessMode Mode) { - SmallVector PathUtf16; + SmallVector PathExts; + PathExts.push_back(""); + PathExts.push_back(".exe"); // FIXME: This must be in %PATHEXT%. + if (const char *PathExtEnv = std::getenv("PATHEXT")) + SplitString(PathExtEnv, PathExts, ";"); - if (std::error_code EC = widenPath(Path, PathUtf16)) - return EC; + DWORD Attributes = INVALID_FILE_ATTRIBUTES; + + for (StringRef Ext : PathExts) { + SmallVector PathUtf16; + + if (std::error_code EC = widenPath(Path + Ext, PathUtf16)) + return EC; - DWORD Attributes = ::GetFileAttributesW(PathUtf16.begin()); + Attributes = ::GetFileAttributesW(PathUtf16.begin()); + + if (Attributes != INVALID_FILE_ATTRIBUTES) + // the file exists + break; + } if (Attributes == INVALID_FILE_ATTRIBUTES) { // See if the file didn't actually exist.