Skip to content

Commit

Permalink
RROW-1500: [C++] Do not ignore return value from truncate in MemoryMa…
Browse files Browse the repository at this point in the history
…ppedFile::Create

Author: Amir Malekpour <a.malekpour@gmail.com>
  • Loading branch information
amirma committed Sep 19, 2017
1 parent e1d9c7f commit 7e02162
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cpp/src/arrow/io/file.cc
Expand Up @@ -580,13 +580,21 @@ MemoryMappedFile::~MemoryMappedFile() {}

Status MemoryMappedFile::Create(const std::string& path, int64_t size,
std::shared_ptr<MemoryMappedFile>* out) {
int ret;
std::shared_ptr<FileOutputStream> file;
RETURN_NOT_OK(FileOutputStream::Open(path, &file));
#ifdef _MSC_VER
_chsize_s(file->file_descriptor(), static_cast<size_t>(size));
ret = _chsize_s(file->file_descriptor(), static_cast<size_t>(size));
#else
ftruncate(file->file_descriptor(), static_cast<size_t>(size));
ret = ftruncate(file->file_descriptor(), static_cast<size_t>(size));
#endif

if (ret != 0) {
std::stringstream ss;
ss << "Unable to create file, error: " << std::strerror(errno);
return Status::IOError(ss.str());
}

RETURN_NOT_OK(file->Close());
return MemoryMappedFile::Open(path, FileMode::READWRITE, out);
}
Expand Down

0 comments on commit 7e02162

Please sign in to comment.