diff options
author | Yun Peng <pcloudy@google.com> | 2016-04-11 12:40:00 +0000 |
---|---|---|
committer | Lukacs Berki <lberki@google.com> | 2016-04-11 14:32:18 +0000 |
commit | 5fea2289175589d18a639433cc9b28d3cedc1001 (patch) | |
tree | b05302a9db6601ef954ffca0ea6cf58bdab843fe /third_party | |
parent | c0c88848b82be9fb3ea0b5af30ff154df85240d8 (diff) |
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
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/ijar/mapped_file_windows.cc | 21 |
1 files changed, 17 insertions, 4 deletions
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<char*>(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<char*>( 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<char*>( 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; |