From 5fea2289175589d18a639433cc9b28d3cedc1001 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Mon, 11 Apr 2016 12:40:00 +0000 Subject: Add prefix to file path in ijar to allow file path longer than 260 on Windows -- Change-Id: Ia176408e9b59caa85da7eb63fd3d9251a1d3fb40 Reviewed-on: https://bazel-review.googlesource.com/#/c/3328/ MOS_MIGRATED_REVID=119522458 --- third_party/ijar/mapped_file_windows.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'third_party/ijar/mapped_file_windows.cc') diff --git a/third_party/ijar/mapped_file_windows.cc b/third_party/ijar/mapped_file_windows.cc index 6b4ba30ce9..3a928c5191 100644 --- a/third_party/ijar/mapped_file_windows.cc +++ b/third_party/ijar/mapped_file_windows.cc @@ -38,6 +38,15 @@ void PrintLastError(const char* op) { LocalFree(message); } +char* ToUnicodePath(const char* path) { + // Add \\?\ as prefix to enable unicode path which allows path length longer + // than 260 + int length = strlen(path) + 5; + char* unicode_path = reinterpret_cast(malloc(length)); + snprintf(unicode_path, length, "\\\\?\\%s", path); + return unicode_path; +} + struct MappedInputFileImpl { HANDLE file_; HANDLE mapping_; @@ -55,9 +64,11 @@ MappedInputFile::MappedInputFile(const char* name) { char* path = reinterpret_cast( cygwin_create_path(CCP_POSIX_TO_WIN_A, name)); - HANDLE file = CreateFile( - path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + char* unicode_path = ToUnicodePath(path); free(path); + HANDLE file = CreateFile(unicode_path, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, 0, NULL); + free(unicode_path); if (file == INVALID_HANDLE_VALUE) { PrintLastError("CreateFile()"); return; @@ -138,9 +149,11 @@ MappedOutputFile::MappedOutputFile(const char* name, u8 estimated_size) { char* path = reinterpret_cast( cygwin_create_path(CCP_POSIX_TO_WIN_A, name)); - HANDLE file = CreateFile( - path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); + char* unicode_path = ToUnicodePath(path); free(path); + HANDLE file = CreateFile(unicode_path, GENERIC_READ | GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, 0, NULL); + free(unicode_path); if (file == INVALID_HANDLE_VALUE) { PrintLastError("CreateFile()"); return; -- cgit v1.2.3