Skip to content
Permalink
Browse files

ARROW-5700: [C++] Try to produce better errors on Windows

Using GetLastError() if possible may produce more precise diagnostics than errno, since typically one errno can map to several different Windows error codes.

Author: Antoine Pitrou <antoine@python.org>

Closes #4724 from pitrou/ARROW-5700-better-win-error-message and squashes the following commits:

5f866c2 <Antoine Pitrou> ARROW-5700:  Try to produce better errors on Windows
  • Loading branch information
pitrou authored and wesm committed Jun 27, 2019
1 parent 68c95b2 commit 263c28721048b042a586264439c65115123d39b8
Showing with 9 additions and 0 deletions.
  1. +9 −0 cpp/src/arrow/util/io-util.cc
@@ -407,6 +407,13 @@ static inline Status CheckFileOpResult(int ret, int errno_actual,
const PlatformFilename& file_name,
const char* opname) {
if (ret == -1) {
#ifdef _WIN32
int winerr = GetLastError();
if (winerr != ERROR_SUCCESS) {
return Status::IOError("Failed to ", opname, " file '", file_name.ToString(),
"', error: ", WinErrorMessage(winerr));
}
#endif
return Status::IOError("Failed to ", opname, " file '", file_name.ToString(),
"', error: ", ErrnoMessage(errno_actual));
}
@@ -416,6 +423,7 @@ static inline Status CheckFileOpResult(int ret, int errno_actual,
Status FileOpenReadable(const PlatformFilename& file_name, int* fd) {
int ret, errno_actual;
#if defined(_WIN32)
SetLastError(0);
errno_actual = _wsopen_s(fd, file_name.ToNative().c_str(),
_O_RDONLY | _O_BINARY | _O_NOINHERIT, _SH_DENYNO, _S_IREAD);
ret = *fd;
@@ -446,6 +454,7 @@ Status FileOpenWritable(const PlatformFilename& file_name, bool write_only, bool
int ret, errno_actual;

#if defined(_WIN32)
SetLastError(0);
int oflag = _O_CREAT | _O_BINARY | _O_NOINHERIT;
int pmode = _S_IREAD | _S_IWRITE;

0 comments on commit 263c287

Please sign in to comment.
You can’t perform that action at this time.