From da71649991029bcfabc429b26685bf17bb3d48d1 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 10 Feb 2013 17:30:18 +0100 Subject: [PATCH] unix, windows: make uv_fs_t.statbuf public 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 #704. --- include/uv-private/uv-unix.h | 1 - include/uv-private/uv-win.h | 1 - include/uv.h | 1 + src/fs-poll.c | 2 +- src/win/fs.c | 8 ++++---- test/test-fs.c | 8 ++++---- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/uv-private/uv-unix.h b/include/uv-private/uv-unix.h index 74b4e81a6f..fe32c4b8ac 100644 --- a/include/uv-private/uv-unix.h +++ b/include/uv-private/uv-unix.h @@ -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; diff --git a/include/uv-private/uv-win.h b/include/uv-private/uv-win.h index ef58401d5a..876b131209 100644 --- a/include/uv-private/uv-win.h +++ b/include/uv-private/uv-win.h @@ -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; \ diff --git a/include/uv.h b/include/uv.h index 8ec4c623f1..249952fc3e 100644 --- a/include/uv.h +++ b/include/uv.h @@ -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 }; diff --git a/src/fs-poll.c b/src/fs-poll.c index 8d736caba9..ad27f18432 100644 --- a/src/fs-poll.c +++ b/src/fs-poll.c @@ -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)) diff --git a/src/win/fs.c b/src/win/fs.c index 9b920c817a..60e67a41d5 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -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. */ @@ -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); } @@ -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; } diff --git a/test/test-fs.c b/test/test-fs.c index ddc3c73b13..0016b3bede 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -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, @@ -543,7 +543,7 @@ 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; @@ -551,7 +551,7 @@ static void check_utime(const char* path, double atime, double mtime) { ASSERT(r == 0); ASSERT(req.result == 0); - s = req.ptr; + s = &req.statbuf; #if defined(_WIN32) || defined(_AIX) ASSERT(s->st_atime == atime);