Index: include/llvm/Support/FileSystem.h =================================================================== --- include/llvm/Support/FileSystem.h +++ include/llvm/Support/FileSystem.h @@ -378,9 +378,7 @@ /// /// @param Path Input path. /// @returns True if we can execute it, false otherwise. -inline bool can_execute(const Twine &Path) { - return !access(Path, AccessMode::Execute); -} +bool can_execute(const Twine &Path); /// @brief Can we write this file? /// Index: lib/Support/Unix/Path.inc =================================================================== --- lib/Support/Unix/Path.inc +++ lib/Support/Unix/Path.inc @@ -325,6 +325,10 @@ return std::error_code(); } +bool can_execute(const Twine &Path) { + return !access(Path, AccessMode::Execute); +} + bool equivalent(file_status A, file_status B) { assert(status_known(A) && status_known(B)); return A.fs_st_dev == B.fs_st_dev && 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 @@ -302,6 +303,21 @@ return std::error_code(); } +bool can_execute(const Twine &Path) { + 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, ";"); + + for (StringRef Ext : PathExts) { + if (!access(Path + Ext, AccessMode::Execute)) + return true; + } + + return false; +} + bool equivalent(file_status A, file_status B) { assert(status_known(A) && status_known(B)); return A.FileIndexHigh == B.FileIndexHigh &&