File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -53,11 +53,12 @@ class MemoryMappedSource::Impl {
5353 Status Open (const std::string& path, MemorySource::AccessMode mode) {
5454 if (is_open_) { return Status::IOError (" A file is already open" ); }
5555
56- prot_flags = PROT_READ;
56+ uint8_t prot_flags = PROT_READ;
5757
5858 if (mode == MemorySource::READ_WRITE) {
5959 file_ = fopen (path.c_str (), " r+b" );
6060 prot_flags |= PROT_WRITE;
61+ is_writable_ = true ;
6162 } else {
6263 file_ = fopen (path.c_str (), " rb" );
6364 }
@@ -89,13 +90,15 @@ class MemoryMappedSource::Impl {
8990
9091 uint8_t * data () { return data_; }
9192
92- bool writable () { return (prot_flags & PROT_WRITE) == PROT_WRITE; }
93+ bool writable () { return is_writable_; }
94+
95+ bool opened () { return is_open_; }
9396
9497 private:
9598 FILE* file_;
9699 int64_t size_;
97100 bool is_open_;
98- uint8_t prot_flags ;
101+ bool is_writable_ ;
99102
100103 // The memory map
101104 uint8_t * data_;
@@ -136,7 +139,7 @@ Status MemoryMappedSource::ReadAt(
136139}
137140
138141Status MemoryMappedSource::Write (int64_t position, const uint8_t * data, int64_t nbytes) {
139- if (!impl_->writable ()) {
142+ if (!impl_->opened () || !impl_-> writable ()) {
140143 return Status::IOError (" Unable to write" );
141144 }
142145 if (position < 0 || position >= impl_->size ()) {
You can’t perform that action at this time.
0 commit comments