diff options
author | Paul Robinson <paul_robinson@playstation.sony.com> | 2014-11-24 18:05:29 +0000 |
---|---|---|
committer | Paul Robinson <paul_robinson@playstation.sony.com> | 2014-11-24 18:05:29 +0000 |
commit | c38deee8076f300e29214648108eddf33db3e200 (patch) | |
tree | 77fc1d8193c2ab93d0bfa168f313235f4dc652aa /llvm/lib/Support/Windows | |
parent | 397a25e7cd945723859e76241269ac0657526c7a (diff) | |
download | bcm5719-llvm-c38deee8076f300e29214648108eddf33db3e200.tar.gz bcm5719-llvm-c38deee8076f300e29214648108eddf33db3e200.zip |
More long path name support on Windows, this time in program execution.
Allows long paths for the executable and redirected stdin/stdout/stderr.
Addresses PR21563.
llvm-svn: 222671
Diffstat (limited to 'llvm/lib/Support/Windows')
-rw-r--r-- | llvm/lib/Support/Windows/Path.inc | 12 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Program.inc | 15 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/WindowsSupport.h | 6 |
3 files changed, 24 insertions, 9 deletions
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index 365031cf150..adb9a60857f 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -44,6 +44,7 @@ using namespace llvm; using llvm::sys::windows::UTF8ToUTF16; using llvm::sys::windows::UTF16ToUTF8; +using llvm::sys::path::widenPath; static std::error_code windows_error(DWORD E) { return mapWindowsError(E); @@ -59,11 +60,15 @@ static bool is_separator(const wchar_t value) { } } +namespace llvm { +namespace sys { +namespace path { + // Convert a UTF-8 path to UTF-16. Also, if the absolute equivalent of the // path is longer than CreateDirectory can tolerate, make it absolute and // prefixed by '\\?\'. -static std::error_code widenPath(const Twine &Path8, - SmallVectorImpl<wchar_t> &Path16) { +std::error_code widenPath(const Twine &Path8, + SmallVectorImpl<wchar_t> &Path16) { const size_t MaxDirLen = MAX_PATH - 12; // Must leave room for 8.3 filename. // Several operations would convert Path8 to SmallString; more efficient to @@ -111,9 +116,8 @@ static std::error_code widenPath(const Twine &Path8, // Just use the caller's original path. return UTF8ToUTF16(Path8Str, Path16); } +} // end namespace path -namespace llvm { -namespace sys { namespace fs { std::string getMainExecutable(const char *argv0, void *MainExecAddr) { diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc index 72c2a58688d..6467dddb3da 100644 --- a/llvm/lib/Support/Windows/Program.inc +++ b/llvm/lib/Support/Windows/Program.inc @@ -117,14 +117,19 @@ static HANDLE RedirectIO(const StringRef *path, int fd, std::string* ErrMsg) { sa.bInheritHandle = TRUE; SmallVector<wchar_t, 128> fnameUnicode; - if (windows::UTF8ToUTF16(fname, fnameUnicode)) - return INVALID_HANDLE_VALUE; - + if (path->empty()) { + // Don't play long-path tricks on "NUL". + if (windows::UTF8ToUTF16(fname, fnameUnicode)) + return INVALID_HANDLE_VALUE; + } else { + if (path::widenPath(fname, fnameUnicode)) + return INVALID_HANDLE_VALUE; + } h = CreateFileW(fnameUnicode.data(), fd ? GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE) { - MakeErrMsg(ErrMsg, std::string(fname) + ": Can't open file for " + + MakeErrMsg(ErrMsg, fname + ": Can't open file for " + (fd ? "input: " : "output: ")); } @@ -322,7 +327,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, fflush(stderr); SmallVector<wchar_t, MAX_PATH> ProgramUtf16; - if (std::error_code ec = windows::UTF8ToUTF16(Program, ProgramUtf16)) { + if (std::error_code ec = path::widenPath(Program, ProgramUtf16)) { SetLastError(ec.value()); MakeErrMsg(ErrMsg, std::string("Unable to convert application name to UTF-16")); diff --git a/llvm/lib/Support/Windows/WindowsSupport.h b/llvm/lib/Support/Windows/WindowsSupport.h index 6d9c5fb24ff..1d1cedcce29 100644 --- a/llvm/lib/Support/Windows/WindowsSupport.h +++ b/llvm/lib/Support/Windows/WindowsSupport.h @@ -30,6 +30,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" #include "llvm/Config/config.h" // Get build system configuration settings #include "llvm/Support/Compiler.h" #include <system_error> @@ -162,6 +163,11 @@ c_str(SmallVectorImpl<T> &str) { } namespace sys { +namespace path { +std::error_code widenPath(const Twine &Path8, + SmallVectorImpl<wchar_t> &Path16); +} // end namespace path + namespace windows { std::error_code UTF8ToUTF16(StringRef utf8, SmallVectorImpl<wchar_t> &utf16); std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, |