fix fs_file_noent on windows

This commit is contained in:
Igor Zinkovsky 2011-09-08 18:23:19 -07:00
parent 0d373eb0b1
commit cfa1423f96
4 changed files with 23 additions and 16 deletions

View File

@ -31,12 +31,6 @@
#define COUNTOF(a) (sizeof(a) / sizeof(a[0]))
/* Used for the uv_fs_ functions */
#define SET_REQ_RESULT(req, result_value) \
req->result = (result_value); \
if (req->result == -1) { \
req->errorno = errno; \
}
struct uv_ares_task_s {
UV_HANDLE_FIELDS

View File

@ -96,6 +96,7 @@ char* uv_strerror(uv_err_t err) {
uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case ERROR_SUCCESS: return UV_OK;
case ERROR_FILE_NOT_FOUND: return UV_ENOENT;
case ERROR_NOACCESS: return UV_EACCESS;
case WSAEACCES: return UV_EACCESS;
case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE;

View File

@ -82,6 +82,17 @@
req->last_error = error; \
req->flags |= UV_FS_LAST_ERROR_SET;
#define SET_REQ_RESULT(req, result_value) \
req->result = (result_value); \
if (req->result == -1) { \
req->errorno = uv_translate_sys_error(_doserrno); \
}
#define SET_REQ_RESULT_WIN32_ERROR(req, sys_errno) \
req->result = -1; \
req->errorno = uv_translate_sys_error(sys_errno); \
SET_REQ_LAST_ERROR(req, sys_errno);
void uv_fs_init() {
_fmode = _O_BINARY;
@ -227,8 +238,8 @@ void fs__open(uv_fs_t* req, const char* path, int flags, int mode) {
attributes,
NULL);
if (file == INVALID_HANDLE_VALUE) {
result = -1;
goto end;
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
}
result = _open_osfhandle((intptr_t)file, flags);
end:
@ -356,9 +367,8 @@ void fs__readdir(uv_fs_t* req, const char* path, int flags) {
free(path2);
if(dir == INVALID_HANDLE_VALUE) {
result = -1;
SET_REQ_LAST_ERROR(req, GetLastError());
goto done;
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
}
buf = (char*)malloc(buf_size);
@ -439,9 +449,10 @@ void fs__rename(uv_fs_t* req, const char* path, const char* new_path) {
void fs__fsync(uv_fs_t* req, uv_file file) {
int result = FlushFileBuffers((HANDLE)_get_osfhandle(file)) ? 0 : -1;
if (result == -1) {
SET_REQ_LAST_ERROR(req, GetLastError());
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
} else {
SET_REQ_RESULT(req, result);
}
SET_REQ_RESULT(req, result);
}
@ -560,9 +571,10 @@ void fs__futime(uv_fs_t* req, uv_file file, double atime, double mtime) {
void fs__link(uv_fs_t* req, const char* path, const char* new_path) {
int result = CreateHardLinkA(new_path, path, NULL) ? 0 : -1;
if (result == -1) {
SET_REQ_LAST_ERROR(req, GetLastError());
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
} else {
SET_REQ_RESULT(req, result);
}
SET_REQ_RESULT(req, result);
}

View File

@ -391,7 +391,7 @@ TEST_IMPL(fs_file_noent) {
loop = uv_default_loop();
r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
ASSERT(r == -1);
ASSERT(r == 0);
ASSERT(req.result == -1);
ASSERT(uv_last_error(loop).code == UV_ENOENT);
uv_fs_req_cleanup(&req);