Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: check for fd==-1 in uv_fs functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Oct 12, 2011
1 parent e0a4e72 commit 72fb469
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/win/fs.c
Expand Up @@ -72,7 +72,6 @@
req->flags |= UV_FS_ASYNC_QUEUED; \
uv_ref((loop));


#define SET_UV_LAST_ERROR_FROM_REQ(req) \
if (req->flags & UV_FS_LAST_ERROR_SET) { \
uv__set_sys_error(req->loop, req->last_error); \
Expand All @@ -96,6 +95,14 @@
req->errorno = uv_translate_sys_error(sys_errno); \
SET_REQ_LAST_ERROR(req, sys_errno);

#define VERIFY_UV_FILE(file, req) \
if (file == -1) { \
req->result = -1; \
req->errorno = UV_EBADF; \
req->last_error = ERROR_SUCCESS; \
return; \
}


void uv_fs_init() {
_fmode = _O_BINARY;
Expand Down Expand Up @@ -241,7 +248,11 @@ void fs__open(uv_fs_t* req, const char* path, int flags, int mode) {
}

void fs__close(uv_fs_t* req, uv_file file) {
int result = _close(file);
int result;

VERIFY_UV_FILE(file, req);

result = _close(file);
SET_REQ_RESULT(req, result);
}

Expand All @@ -253,6 +264,8 @@ void fs__read(uv_fs_t* req, uv_file file, void *buf, size_t length,
LARGE_INTEGER offset_;
DWORD bytes;

VERIFY_UV_FILE(file, req);

handle = (HANDLE) _get_osfhandle(file);
if (handle == INVALID_HANDLE_VALUE) {
SET_REQ_RESULT(req, -1);
Expand Down Expand Up @@ -291,6 +304,8 @@ void fs__write(uv_fs_t* req, uv_file file, void *buf, size_t length,
LARGE_INTEGER offset_;
DWORD bytes;

VERIFY_UV_FILE(file, req);

handle = (HANDLE) _get_osfhandle(file);
if (handle == INVALID_HANDLE_VALUE) {
SET_REQ_RESULT(req, -1);
Expand Down Expand Up @@ -425,6 +440,8 @@ void fs__stat(uv_fs_t* req, const char* path) {
void fs__fstat(uv_fs_t* req, uv_file file) {
int result;

VERIFY_UV_FILE(file, req);

result = _fstati64(file, &req->stat);
if (result == -1) {
req->ptr = NULL;
Expand All @@ -443,7 +460,11 @@ 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;
int result;

VERIFY_UV_FILE(file, req);

result = FlushFileBuffers((HANDLE)_get_osfhandle(file)) ? 0 : -1;
if (result == -1) {
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
} else {
Expand All @@ -453,7 +474,11 @@ void fs__fsync(uv_fs_t* req, uv_file file) {


void fs__ftruncate(uv_fs_t* req, uv_file file, off_t offset) {
int result = _chsize(file, offset);
int result;

VERIFY_UV_FILE(file, req);

result = _chsize(file, offset);
SET_REQ_RESULT(req, result);
}

Expand Down Expand Up @@ -511,6 +536,8 @@ void fs__fchmod(uv_fs_t* req, uv_file file, int mode) {
IO_STATUS_BLOCK io_status;
FILE_BASIC_INFORMATION file_info;

VERIFY_UV_FILE(file, req);

handle = (HANDLE)_get_osfhandle(file);

nt_status = pNtQueryInformationFile(handle,
Expand Down Expand Up @@ -559,6 +586,9 @@ void fs__utime(uv_fs_t* req, const char* path, double atime, double mtime) {
void fs__futime(uv_fs_t* req, uv_file file, double atime, double mtime) {
int result;
struct _utimbuf b = {(time_t)atime, (time_t)mtime};

VERIFY_UV_FILE(file, req);

result = _futime(file, &b);
SET_REQ_RESULT(req, result);
}
Expand Down

0 comments on commit 72fb469

Please sign in to comment.