Adapt ijar for WSL
The behavior of ftruncate on WSL is not same as standard Linux due to a bug, it'll fail on maped file.
This commit fix the bug by munmap the file before ftruncate.
Closes #2108.
--
Reviewed-on: https://github.com/bazelbuild/bazel/pull/2108
MOS_MIGRATED_REVID=140134115
diff --git a/third_party/ijar/mapped_file_unix.cc b/third_party/ijar/mapped_file_unix.cc
index f7668a5..d5a0b57 100644
--- a/third_party/ijar/mapped_file_unix.cc
+++ b/third_party/ijar/mapped_file_unix.cc
@@ -87,6 +87,7 @@
struct MappedOutputFileImpl {
int fd_;
+ int mmap_length_;
};
MappedOutputFile::MappedOutputFile(const char* name, u8 estimated_size) {
@@ -119,6 +120,7 @@
impl_ = new MappedOutputFileImpl();
impl_->fd_ = fd;
+ impl_->mmap_length_ = mmap_length;
buffer_ = reinterpret_cast<u1*>(mapped);
opened_ = true;
}
@@ -129,6 +131,7 @@
}
int MappedOutputFile::Close(int size) {
+ munmap(buffer_, impl_->mmap_length_);
if (ftruncate(impl_->fd_, size) < 0) {
snprintf(errmsg, MAX_ERROR, "ftruncate(): %s", strerror(errno));
errmsg_ = errmsg;