Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3320e9e authored by Pirama Arumuga Nainar's avatar Pirama Arumuga Nainar Committed by android-build-merger
Browse files

Merge "Support zero-length mapped files" am: 2009e320 am: 747e647b

am: 4c88d1ae

Change-Id: I2f19669b7f6d7224497c7c44857b8ed9b2d4e13f
parents 2986dd4d 4c88d1ae
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -41,7 +41,14 @@ std::unique_ptr<MappedFile> MappedFile::FromFd(int fd, off64_t offset, size_t le
  HANDLE handle =
      CreateFileMapping(reinterpret_cast<HANDLE>(_get_osfhandle(fd)), nullptr,
                        (prot & PROT_WRITE) ? PAGE_READWRITE : PAGE_READONLY, 0, 0, nullptr);
  if (handle == nullptr) return nullptr;
  if (handle == nullptr) {
    // http://b/119818070 "app crashes when reading asset of zero length".
    // Return a MappedFile that's only valid for reading the size.
    if (length == 0) {
      return std::unique_ptr<MappedFile>(new MappedFile{nullptr, 0, 0, nullptr});
    }
    return nullptr;
  }
  void* base = MapViewOfFile(handle, (prot & PROT_WRITE) ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ, 0,
                             file_offset, file_length);
  if (base == nullptr) {