Skip to content

Commit 22e6128

Browse files
committed
Simplify error check
1 parent 5559b8d commit 22e6128

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cpp/src/arrow/ipc/memory.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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

138141
Status 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()) {

0 commit comments

Comments
 (0)