Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions cpp/src/arrow/io/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ struct PlatformFilename {
};
#endif

static inline Status CheckOpenResult(int ret, int errno_actual,
const PlatformFilename& file_name) {
static inline Status CheckFileOpResult(int ret, int errno_actual,
const PlatformFilename& file_name,
const std::string& opname) {
if (ret == -1) {
// TODO: errno codes to strings
std::stringstream ss;
ss << "Failed to open local file: " << file_name.string();
ss << "Failed to " << opname << " file: " << file_name.string();
ss << " , error: " << std::strerror(errno_actual);
return Status::IOError(ss.str());
}
return Status::OK();
Expand Down Expand Up @@ -168,7 +169,7 @@ static inline Status FileOpenReadable(const PlatformFilename& file_name, int* fd
errno_actual = errno;
#endif

return CheckOpenResult(ret, errno_actual, file_name);
return CheckFileOpResult(ret, errno_actual, file_name, "open local");
}

static inline Status FileOpenWriteable(const PlatformFilename& file_name, bool write_only,
Expand Down Expand Up @@ -211,7 +212,7 @@ static inline Status FileOpenWriteable(const PlatformFilename& file_name, bool w

ret = *fd = open(file_name.c_str(), oflag, ARROW_WRITE_SHMODE);
#endif
return CheckOpenResult(ret, errno_actual, file_name);
return CheckFileOpResult(ret, errno_actual, file_name, "open local");
}

static inline Status FileTell(int fd, int64_t* pos) {
Expand Down Expand Up @@ -599,13 +600,21 @@ MemoryMappedFile::~MemoryMappedFile() {}

Status MemoryMappedFile::Create(const std::string& path, int64_t size,
std::shared_ptr<MemoryMappedFile>* out) {
int ret;
errno_t errno_actual;
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));
errno_actual = _chsize_s(file->file_descriptor(), static_cast<size_t>(size));
ret = errno_actual == 0 ? 0 : -1;
#else
ftruncate(file->file_descriptor(), static_cast<size_t>(size));
ret = ftruncate(file->file_descriptor(), static_cast<size_t>(size));
errno_actual = errno;
#endif

RETURN_NOT_OK(CheckFileOpResult(ret, errno_actual, PlatformFilename(path), "truncate"));

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