diff options
Diffstat (limited to 'base/file_util.cc')
-rw-r--r-- | base/file_util.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index 4cde773..8d1b517 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -267,6 +267,20 @@ MemoryMappedFile::~MemoryMappedFile() { CloseHandles(); } +bool MemoryMappedFile::Initialize(base::PlatformFile file) { + if (IsValid()) + return false; + + file_ = file; + + if (!MapFileToMemoryInternal()) { + CloseHandles(); + return false; + } + + return true; +} + bool MemoryMappedFile::Initialize(const FilePath& file_name) { if (IsValid()) return false; @@ -279,6 +293,19 @@ bool MemoryMappedFile::Initialize(const FilePath& file_name) { return true; } +bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) { + file_ = base::CreatePlatformFile(file_name, + base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, + NULL); + + if (file_ == base::kInvalidPlatformFileValue) { + LOG(ERROR) << "Couldn't open " << file_name.value(); + return false; + } + + return MapFileToMemoryInternal(); +} + bool MemoryMappedFile::IsValid() { return data_ != NULL; } |