Skip to content

Commit

Permalink
unix, windows: make uv_fs_t.statbuf public
Browse files Browse the repository at this point in the history
Make the statbuf field public. This means you no longer have to use
req->ptr - though that still works and will continue to work for the
foreseeable future.

Fixes joyent#704.
  • Loading branch information
bnoordhuis committed Feb 10, 2013
1 parent fadfeaf commit da71649
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion include/uv-private/uv-unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ typedef struct {
double atime; \
double mtime; \
struct uv__work work_req; \
struct stat statbuf; \

#define UV_WORK_PRIVATE_FIELDS \
struct uv__work work_req;
Expand Down
1 change: 0 additions & 1 deletion include/uv-private/uv-win.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
size_t length; \
int64_t offset; \
}; \
struct _stati64 stat; \
struct { \
double atime; \
double mtime; \
Expand Down
1 change: 1 addition & 0 deletions include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ struct uv_fs_s {
void* ptr;
const char* path;
uv_err_code errorno;
uv_statbuf_t statbuf; /* Stores the result of uv_fs_stat and uv_fs_fstat. */
UV_FS_PRIVATE_FIELDS
};

Expand Down
2 changes: 1 addition & 1 deletion src/fs-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static void poll_cb(uv_fs_t* req) {
goto out;
}

statbuf = req->ptr;
statbuf = &req->statbuf;

if (ctx->busy_polling != 0)
if (ctx->busy_polling < 0 || !statbuf_eq(&ctx->statbuf, statbuf))
Expand Down
8 changes: 4 additions & 4 deletions src/win/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ INLINE static void fs__stat_impl(uv_fs_t* req, int do_lstat) {
return;
}

if (fs__stat_handle(handle, &req->stat) != 0) {
if (fs__stat_handle(handle, &req->statbuf) != 0) {
DWORD error = GetLastError();
if (do_lstat && error == ERROR_SYMLINK_NOT_SUPPORTED) {
/* We opened a reparse point but it was not a symlink. Try again. */
Expand All @@ -904,7 +904,7 @@ INLINE static void fs__stat_impl(uv_fs_t* req, int do_lstat) {
return;
}

req->ptr = &req->stat;
req->ptr = &req->statbuf;
req->result = 0;
CloseHandle(handle);
}
Expand Down Expand Up @@ -935,12 +935,12 @@ static void fs__fstat(uv_fs_t* req) {
return;
}

if (fs__stat_handle(handle, &req->stat) != 0) {
if (fs__stat_handle(handle, &req->statbuf) != 0) {
SET_REQ_WIN32_ERROR(req, GetLastError());
return;
}

req->ptr = &req->stat;
req->ptr = &req->statbuf;
req->result = 0;
}

Expand Down
8 changes: 4 additions & 4 deletions test/test-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ static char test_buf[] = "test-buffer\n";
static void check_permission(const char* filename, int mode) {
int r;
uv_fs_t req;
struct stat* s;
uv_statbuf_t* s;

r = uv_fs_stat(uv_default_loop(), &req, filename, NULL);
ASSERT(r == 0);
ASSERT(req.result == 0);

s = req.ptr;
s = &req.statbuf;
#ifdef _WIN32
/*
* On Windows, chmod can only modify S_IWUSR (_S_IWRITE) bit,
Expand Down Expand Up @@ -543,15 +543,15 @@ TEST_IMPL(fs_file_loop) {
}

static void check_utime(const char* path, double atime, double mtime) {
struct stat* s;
uv_statbuf_t* s;
uv_fs_t req;
int r;

r = uv_fs_stat(loop, &req, path, NULL);
ASSERT(r == 0);

ASSERT(req.result == 0);
s = req.ptr;
s = &req.statbuf;

#if defined(_WIN32) || defined(_AIX)
ASSERT(s->st_atime == atime);
Expand Down

0 comments on commit da71649

Please sign in to comment.