aboutsummaryrefslogtreecommitdiff
path: root/deps/uv/src/win/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/win/fs.c')
-rw-r--r--deps/uv/src/win/fs.c77
1 files changed, 50 insertions, 27 deletions
diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c
index 0475f43307..a51f8f013f 100644
--- a/deps/uv/src/win/fs.c
+++ b/deps/uv/src/win/fs.c
@@ -42,27 +42,35 @@
#define QUEUE_FS_TP_JOB(loop, req) \
- if (!QueueUserWorkItem(&uv_fs_thread_proc, \
- req, \
- WT_EXECUTEDEFAULT)) { \
- return uv_translate_sys_error(GetLastError()); \
- } \
- uv__req_register(loop, req);
+ do { \
+ if (!QueueUserWorkItem(&uv_fs_thread_proc, \
+ req, \
+ WT_EXECUTEDEFAULT)) { \
+ return uv_translate_sys_error(GetLastError()); \
+ } \
+ uv__req_register(loop, req); \
+ } while (0)
#define SET_REQ_RESULT(req, result_value) \
- req->result = (result_value); \
- if (req->result == -1) { \
- req->sys_errno_ = _doserrno; \
- req->result = uv_translate_sys_error(req->sys_errno_); \
- }
+ do { \
+ req->result = (result_value); \
+ if (req->result == -1) { \
+ req->sys_errno_ = _doserrno; \
+ req->result = uv_translate_sys_error(req->sys_errno_); \
+ } \
+ } while (0)
#define SET_REQ_WIN32_ERROR(req, sys_errno) \
- req->sys_errno_ = (sys_errno); \
- req->result = uv_translate_sys_error(req->sys_errno_); \
+ do { \
+ req->sys_errno_ = (sys_errno); \
+ req->result = uv_translate_sys_error(req->sys_errno_); \
+ } while (0)
#define SET_REQ_UV_ERROR(req, uv_errno, sys_errno) \
- req->result = (uv_errno); \
- req->sys_errno_ = (sys_errno); \
+ do { \
+ req->result = (uv_errno); \
+ req->sys_errno_ = (sys_errno); \
+ } while (0)
#define VERIFY_FD(fd, req) \
if (fd == -1) { \
@@ -75,10 +83,10 @@
(*((uint64_t*) &(filetime)) - 116444736000000000ULL)
#define FILETIME_TO_TIME_T(filetime) \
- (FILETIME_TO_UINT(filetime) / 10000000ULL);
+ (FILETIME_TO_UINT(filetime) / 10000000ULL)
#define FILETIME_TO_TIME_NS(filetime, secs) \
- ((FILETIME_TO_UINT(filetime) - (secs * 10000000ULL)) * 100);
+ ((FILETIME_TO_UINT(filetime) - (secs * 10000000ULL)) * 100)
#define FILETIME_TO_TIMESPEC(ts, filetime) \
do { \
@@ -382,7 +390,7 @@ void fs__open(uv_fs_t* req) {
DWORD disposition;
DWORD attributes = 0;
HANDLE file;
- int result, current_umask;
+ int fd, current_umask;
int flags = req->file_flags;
/* Obtain the active umask. umask() never fails and returns the previous */
@@ -403,8 +411,7 @@ void fs__open(uv_fs_t* req) {
access = FILE_GENERIC_READ | FILE_GENERIC_WRITE;
break;
default:
- result = -1;
- goto end;
+ goto einval;
}
if (flags & _O_APPEND) {
@@ -441,8 +448,7 @@ void fs__open(uv_fs_t* req) {
disposition = CREATE_ALWAYS;
break;
default:
- result = -1;
- goto end;
+ goto einval;
}
attributes |= FILE_ATTRIBUTE_NORMAL;
@@ -471,8 +477,7 @@ void fs__open(uv_fs_t* req) {
attributes |= FILE_FLAG_RANDOM_ACCESS;
break;
default:
- result = -1;
- goto end;
+ goto einval;
}
/* Setting this flag makes it possible to open a directory. */
@@ -497,9 +502,27 @@ void fs__open(uv_fs_t* req) {
}
return;
}
- result = _open_osfhandle((intptr_t) file, flags);
-end:
- SET_REQ_RESULT(req, result);
+
+ fd = _open_osfhandle((intptr_t) file, flags);
+ if (fd < 0) {
+ /* The only known failure mode for _open_osfhandle() is EMFILE, in which
+ * case GetLastError() will return zero. However we'll try to handle other
+ * errors as well, should they ever occur.
+ */
+ if (errno == EMFILE)
+ SET_REQ_UV_ERROR(req, UV_EMFILE, ERROR_TOO_MANY_OPEN_FILES);
+ else if (GetLastError() != ERROR_SUCCESS)
+ SET_REQ_WIN32_ERROR(req, GetLastError());
+ else
+ SET_REQ_WIN32_ERROR(req, UV_UNKNOWN);
+ return;
+ }
+
+ SET_REQ_RESULT(req, fd);
+ return;
+
+ einval:
+ SET_REQ_UV_ERROR(req, UV_EINVAL, ERROR_INVALID_PARAMETER);
}
void fs__close(uv_fs_t* req) {