Commit 7e5e9e7f authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

platform: posix fix open read-only file

Bug: v8:8997
Change-Id: If47a9c4d580b29f67eaadc4b129279b085e428b2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1530812
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Auto-Submit: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60336}
parent 8829f813
......@@ -446,7 +446,8 @@ class PosixMemoryMappedFile final : public OS::MemoryMappedFile {
// static
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name,
FileMode mode) {
if (FILE* file = fopen(name, "r+")) {
const char* fopen_mode = (mode == FileMode::kReadOnly) ? "r" : "r+";
if (FILE* file = fopen(name, fopen_mode)) {
if (fseek(file, 0, SEEK_END) == 0) {
long size = ftell(file); // NOLINT(runtime/int)
if (size == 0) return new PosixMemoryMappedFile(file, nullptr, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment