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

Commit

Permalink
Browse files Browse the repository at this point in the history
windows: include _stat struct into uv_fs_t
  • Loading branch information
Igor Zinkovsky committed Sep 1, 2011
1 parent 836cc20 commit 22197eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 2 additions & 0 deletions include/uv-private/uv-win.h
Expand Up @@ -28,6 +28,7 @@
#include <mswsock.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <sys/stat.h>

#include "tree.h"

Expand Down Expand Up @@ -246,6 +247,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);

#define UV_FS_PRIVATE_FIELDS \
int flags; \
struct _stat stat; \
void* arg0; \
union { \
struct { \
Expand Down
23 changes: 6 additions & 17 deletions src/win/fs.c
Expand Up @@ -234,17 +234,11 @@ void fs__readdir(uv_fs_t* req, const char* path, int flags) {
void fs__stat(uv_fs_t* req, const char* path) {
int result;

req->ptr = malloc(sizeof(struct _stat));
if (!req->ptr) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

result = _stat(path, (struct _stat*)req->ptr);
result = _stat(path, &req->stat);
if (result == -1) {
free(req->ptr);
req->ptr = NULL;
} else {
req->flags |= UV_FS_FREE_PTR;
req->ptr = &req->stat;
}

SET_REQ_RESULT(req, result);
Expand All @@ -254,17 +248,11 @@ void fs__stat(uv_fs_t* req, const char* path) {
void fs__fstat(uv_fs_t* req, uv_file file) {
int result;

req->ptr = malloc(sizeof(struct _stat));
if (!req->ptr) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

result = _fstat(file, (struct _stat*)req->ptr);
result = _fstat(file, &req->stat);
if (result == -1) {
free(req->ptr);
req->ptr = NULL;
} else {
req->flags |= UV_FS_FREE_PTR;
req->ptr = &req->stat;
}

SET_REQ_RESULT(req, result);
Expand Down Expand Up @@ -807,9 +795,10 @@ void uv_fs_req_cleanup(uv_fs_t* req) {

if (req->flags & UV_FS_FREE_PTR && req->ptr) {
free(req->ptr);
req->ptr = NULL;
}

req->ptr = NULL;

if (req->flags & UV_FS_ASYNC_QUEUED) {
uv_unref(loop);
}
Expand Down
5 changes: 2 additions & 3 deletions test/test-fs.c
Expand Up @@ -486,10 +486,10 @@ TEST_IMPL(fs_async_dir) {

TEST_IMPL(fs_async_sendfile) {
int f, r;

/* Setup. */
struct stat s1, s2;

/* Setup. */
uv_init();
unlink("test_file");
unlink("test_file2");

Expand All @@ -509,7 +509,6 @@ TEST_IMPL(fs_async_sendfile) {
ASSERT(r == 0);

/* Test starts here. */
uv_init();
loop = uv_default_loop();

r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
Expand Down

0 comments on commit 22197eb

Please sign in to comment.