Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

windows: check for fd==-1 in uv_fs functions

  • Loading branch information...
Igor Zinkovsky
Igor Zinkovsky committed Oct 12, 2011
1 parent e0a4e72 commit 72fb469a43b4582f85357a7dd00f9821dc45e7be
Showing with 34 additions and 4 deletions.
  1. +34 −4 src/win/fs.c
@@ -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); \
@@ -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;
@@ -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);
}

@@ -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);
@@ -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);
@@ -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;
@@ -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 {
@@ -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);
}

@@ -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,
@@ -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);
}

0 comments on commit 72fb469

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