From 19d7a319ba9598835e195d1ab3df80b96b659404 Mon Sep 17 00:00:00 2001 From: Bitshifter-9 Date: Thu, 27 Nov 2025 09:20:30 +0530 Subject: [PATCH] unix: remove artificial nanosecond truncation in uv_fs_futime The uv__fs_to_timespec function in src/unix/fs.c currently truncates nanoseconds to microseconds. This was originally implemented for consistency with other platforms, but as noted in a TODO comment, utimesat() supports nanosecond resolution. This commit removes the truncation to allow full nanosecond precision where supported by the underlying filesystem. It also improves the double-to-timespec conversion to use rounding, fixing precision issues. --- src/unix/fs.c | 904 ++++++++++++--------------------- test/test-fs.c | 1314 ++++++++++++++++++++---------------------------- 2 files changed, 863 insertions(+), 1355 deletions(-) diff --git a/src/unix/fs.c b/src/unix/fs.c index bd3f59628..58e490123 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -26,134 +26,119 @@ * getting the errno to the right place (req->result or as the return value.) */ -#include "uv.h" #include "internal.h" +#include "uv.h" -#include #include +#include +#include /* PATH_MAX */ #include #include #include #include -#include /* PATH_MAX */ -#include +#include +#include #include #include #include +#include #include #include -#include -#include #if defined(__linux__) -# include +#include #endif #if defined(__sun) -# include -# include +#include +#include #endif #if defined(__APPLE__) -# include +#include #elif defined(__linux__) && !defined(FICLONE) -# include -# define FICLONE _IOW(0x94, 9, int) +#include +#define FICLONE _IOW(0x94, 9, int) #endif #if defined(_AIX) && !defined(_AIX71) -# include +#include #endif -#if defined(__APPLE__) || \ - defined(__DragonFly__) || \ - defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) -# include -# include -#elif defined(__sun) || \ - defined(__MVS__) || \ - defined(__NetBSD__) || \ - defined(__HAIKU__) || \ - defined(__QNX__) -# include +#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__OpenBSD__) || defined(__NetBSD__) +#include +#include +#elif defined(__sun) || defined(__MVS__) || defined(__NetBSD__) || \ + defined(__HAIKU__) || defined(__QNX__) +#include #else -# include +#include #endif #if defined(_AIX) && _XOPEN_SOURCE <= 600 extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */ #endif -#define INIT(subtype) \ - do { \ - if (req == NULL) \ - return UV_EINVAL; \ - UV_REQ_INIT(req, UV_FS); \ - req->fs_type = UV_FS_ ## subtype; \ - req->result = 0; \ - req->ptr = NULL; \ - req->loop = loop; \ - req->path = NULL; \ - req->new_path = NULL; \ - req->bufs = NULL; \ - req->cb = cb; \ - } \ - while (0) +#define INIT(subtype) \ + do { \ + if (req == NULL) \ + return UV_EINVAL; \ + UV_REQ_INIT(req, UV_FS); \ + req->fs_type = UV_FS_##subtype; \ + req->result = 0; \ + req->ptr = NULL; \ + req->loop = loop; \ + req->path = NULL; \ + req->new_path = NULL; \ + req->bufs = NULL; \ + req->cb = cb; \ + } while (0) -#define PATH \ - do { \ - assert(path != NULL); \ - if (cb == NULL) { \ - req->path = path; \ - } else { \ - req->path = uv__strdup(path); \ - if (req->path == NULL) \ - return UV_ENOMEM; \ - } \ - } \ - while (0) +#define PATH \ + do { \ + assert(path != NULL); \ + if (cb == NULL) { \ + req->path = path; \ + } else { \ + req->path = uv__strdup(path); \ + if (req->path == NULL) \ + return UV_ENOMEM; \ + } \ + } while (0) -#define PATH2 \ - do { \ - if (cb == NULL) { \ - req->path = path; \ - req->new_path = new_path; \ - } else { \ - size_t path_len; \ - size_t new_path_len; \ - path_len = strlen(path) + 1; \ - new_path_len = strlen(new_path) + 1; \ - req->path = uv__malloc(path_len + new_path_len); \ - if (req->path == NULL) \ - return UV_ENOMEM; \ - req->new_path = req->path + path_len; \ - memcpy((void*) req->path, path, path_len); \ - memcpy((void*) req->new_path, new_path, new_path_len); \ - } \ - } \ - while (0) - -#define POST \ - do { \ - if (cb != NULL) { \ - uv__req_register(loop); \ - uv__work_submit(loop, \ - &req->work_req, \ - UV__WORK_FAST_IO, \ - uv__fs_work, \ - uv__fs_done); \ - return 0; \ - } \ - else { \ - uv__fs_work(&req->work_req); \ - return req->result; \ - } \ - } \ - while (0) +#define PATH2 \ + do { \ + if (cb == NULL) { \ + req->path = path; \ + req->new_path = new_path; \ + } else { \ + size_t path_len; \ + size_t new_path_len; \ + path_len = strlen(path) + 1; \ + new_path_len = strlen(new_path) + 1; \ + req->path = uv__malloc(path_len + new_path_len); \ + if (req->path == NULL) \ + return UV_ENOMEM; \ + req->new_path = req->path + path_len; \ + memcpy((void *)req->path, path, path_len); \ + memcpy((void *)req->new_path, new_path, new_path_len); \ + } \ + } while (0) +#define POST \ + do { \ + if (cb != NULL) { \ + uv__req_register(loop); \ + uv__work_submit(loop, &req->work_req, UV__WORK_FAST_IO, uv__fs_work, \ + uv__fs_done); \ + return 0; \ + } else { \ + uv__fs_work(&req->work_req); \ + return req->result; \ + } \ + } while (0) static int uv__fs_close(int fd) { int rc; @@ -161,13 +146,12 @@ static int uv__fs_close(int fd) { rc = uv__close_nocancel(fd); if (rc == -1) if (errno == EINTR || errno == EINPROGRESS) - rc = 0; /* The close is in progress, not an error. */ + rc = 0; /* The close is in progress, not an error. */ return rc; } - -static ssize_t uv__fs_fsync(uv_fs_t* req) { +static ssize_t uv__fs_fsync(uv_fs_t *req) { #if defined(__APPLE__) /* Apple's fdatasync and fsync explicitly do NOT flush the drive write cache * to the drive platters. This is in contrast to Linux's fdatasync and fsync @@ -181,7 +165,7 @@ static ssize_t uv__fs_fsync(uv_fs_t* req) { r = fcntl(req->file, F_FULLFSYNC); if (r != 0) - r = fcntl(req->file, 85 /* F_BARRIERFSYNC */); /* fsync + barrier */ + r = fcntl(req->file, 85 /* F_BARRIERFSYNC */); /* fsync + barrier */ if (r != 0) r = fsync(req->file); return r; @@ -190,8 +174,7 @@ static ssize_t uv__fs_fsync(uv_fs_t* req) { #endif } - -static ssize_t uv__fs_fdatasync(uv_fs_t* req) { +static ssize_t uv__fs_fdatasync(uv_fs_t *req) { #if defined(__linux__) || defined(__sun) || defined(__NetBSD__) return fdatasync(req->file); #elif defined(__APPLE__) @@ -202,17 +185,10 @@ static ssize_t uv__fs_fdatasync(uv_fs_t* req) { #endif } - -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) static struct timespec uv__fs_to_timespec(double time) { struct timespec ts; @@ -221,15 +197,11 @@ static struct timespec uv__fs_to_timespec(double time) { if (uv__isnan(time)) return (struct timespec){UTIME_OMIT, UTIME_OMIT}; - ts.tv_sec = time; - ts.tv_nsec = (time - ts.tv_sec) * 1e9; - - /* TODO(bnoordhuis) Remove this. utimesat() has nanosecond resolution but we - * stick to microsecond resolution for the sake of consistency with other - * platforms. I'm the original author of this compatibility hack but I'm - * less convinced it's useful nowadays. - */ - ts.tv_nsec -= ts.tv_nsec % 1000; + ts.tv_sec = time; + { + double frac = (time - ts.tv_sec) * 1e9; + ts.tv_nsec = frac >= 0 ? frac + 0.5 : frac - 0.5; + } if (ts.tv_nsec < 0) { ts.tv_nsec += 1e9; @@ -239,18 +211,11 @@ static struct timespec uv__fs_to_timespec(double time) { } #endif - -static ssize_t uv__fs_futime(uv_fs_t* req) { -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +static ssize_t uv__fs_futime(uv_fs_t *req) { +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -269,32 +234,28 @@ static ssize_t uv__fs_futime(uv_fs_t* req) { #endif } - -static ssize_t uv__fs_mkdtemp(uv_fs_t* req) { - return mkdtemp((char*) req->path) ? 0 : -1; +static ssize_t uv__fs_mkdtemp(uv_fs_t *req) { + return mkdtemp((char *)req->path) ? 0 : -1; } - -static int (*uv__mkostemp)(char*, int); - +static int (*uv__mkostemp)(char *, int); static void uv__mkostemp_initonce(void) { /* z/os doesn't have RTLD_DEFAULT but that's okay * because it doesn't have mkostemp(O_CLOEXEC) either. */ #ifdef RTLD_DEFAULT - uv__mkostemp = (int (*)(char*, int)) dlsym(RTLD_DEFAULT, "mkostemp"); + uv__mkostemp = (int (*)(char *, int))dlsym(RTLD_DEFAULT, "mkostemp"); /* We don't care about errors, but we do want to clean them up. * If there has been no error, then dlerror() will just return * NULL. */ dlerror(); -#endif /* RTLD_DEFAULT */ +#endif /* RTLD_DEFAULT */ } - -static int uv__fs_mkstemp(uv_fs_t* req) { +static int uv__fs_mkstemp(uv_fs_t *req) { static uv_once_t once = UV_ONCE_INIT; int r; #ifdef O_CLOEXEC @@ -302,10 +263,10 @@ static int uv__fs_mkstemp(uv_fs_t* req) { #endif static const char pattern[] = "XXXXXX"; static const size_t pattern_size = sizeof(pattern) - 1; - char* path; + char *path; size_t path_length; - path = (char*) req->path; + path = (char *)req->path; path_length = strlen(path); /* EINVAL can be returned for 2 reasons: @@ -339,7 +300,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) { try to use mkostemp. */ atomic_store_explicit(&no_cloexec_support, 1, memory_order_relaxed); } -#endif /* O_CLOEXEC */ +#endif /* O_CLOEXEC */ if (req->cb != NULL) uv_rwlock_rdlock(&req->loop->cloexec_lock); @@ -365,8 +326,7 @@ clobber: return r; } - -static ssize_t uv__fs_open(uv_fs_t* req) { +static ssize_t uv__fs_open(uv_fs_t *req) { #ifdef O_CLOEXEC return open(req->path, req->flags | O_CLOEXEC, req->mode); #else /* O_CLOEXEC */ @@ -391,23 +351,20 @@ static ssize_t uv__fs_open(uv_fs_t* req) { uv_rwlock_rdunlock(&req->loop->cloexec_lock); return r; -#endif /* O_CLOEXEC */ +#endif /* O_CLOEXEC */ } - -static ssize_t uv__preadv_or_pwritev_emul(int fd, - const struct iovec* bufs, - size_t nbufs, - off_t off, +static ssize_t uv__preadv_or_pwritev_emul(int fd, const struct iovec *bufs, + size_t nbufs, off_t off, int is_pread) { ssize_t total; ssize_t r; size_t i; size_t n; - void* p; + void *p; total = 0; - for (i = 0; i < (size_t) nbufs; i++) { + for (i = 0; i < (size_t)nbufs; i++) { p = bufs[i].iov_base; n = bufs[i].iov_len; @@ -427,50 +384,39 @@ static ssize_t uv__preadv_or_pwritev_emul(int fd, off += r; total += r; - if ((size_t) r < n) + if ((size_t)r < n) return total; } return total; } - #ifdef __linux__ typedef int uv__iovcnt; #else typedef size_t uv__iovcnt; #endif - -static ssize_t uv__preadv_emul(int fd, - const struct iovec* bufs, - uv__iovcnt nbufs, - off_t off) { - return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/1); +static ssize_t uv__preadv_emul(int fd, const struct iovec *bufs, + uv__iovcnt nbufs, off_t off) { + return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/ 1); } - -static ssize_t uv__pwritev_emul(int fd, - const struct iovec* bufs, - uv__iovcnt nbufs, - off_t off) { - return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/0); +static ssize_t uv__pwritev_emul(int fd, const struct iovec *bufs, + uv__iovcnt nbufs, off_t off) { + return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/ 0); } - /* The function pointer cache is an uintptr_t because _Atomic void* * doesn't work on macos/ios/etc... */ -static ssize_t uv__preadv_or_pwritev(int fd, - const struct iovec* bufs, - size_t nbufs, - off_t off, - _Atomic uintptr_t* cache, - int is_pread) { - ssize_t (*f)(int, const struct iovec*, uv__iovcnt, off_t); - void* p; +static ssize_t uv__preadv_or_pwritev(int fd, const struct iovec *bufs, + size_t nbufs, off_t off, + _Atomic uintptr_t *cache, int is_pread) { + ssize_t (*f)(int, const struct iovec *, uv__iovcnt, off_t); + void *p; - p = (void*) atomic_load_explicit(cache, memory_order_relaxed); + p = (void *)atomic_load_explicit(cache, memory_order_relaxed); if (p == NULL) { #ifdef RTLD_DEFAULT /* Try _LARGEFILE_SOURCE version of preadv/pwritev first, @@ -479,38 +425,31 @@ static ssize_t uv__preadv_or_pwritev(int fd, p = dlsym(RTLD_DEFAULT, is_pread ? "preadv64" : "pwritev64"); if (p == NULL) p = dlsym(RTLD_DEFAULT, is_pread ? "preadv" : "pwritev"); - dlerror(); /* Clear errors. */ -#endif /* RTLD_DEFAULT */ + dlerror(); /* Clear errors. */ +#endif /* RTLD_DEFAULT */ if (p == NULL) p = is_pread ? uv__preadv_emul : uv__pwritev_emul; - atomic_store_explicit(cache, (uintptr_t) p, memory_order_relaxed); + atomic_store_explicit(cache, (uintptr_t)p, memory_order_relaxed); } f = p; return f(fd, bufs, nbufs, off); } - -static ssize_t uv__preadv(int fd, - const struct iovec* bufs, - size_t nbufs, +static ssize_t uv__preadv(int fd, const struct iovec *bufs, size_t nbufs, off_t off) { static _Atomic uintptr_t cache; - return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/1); + return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/ 1); } - -static ssize_t uv__pwritev(int fd, - const struct iovec* bufs, - size_t nbufs, +static ssize_t uv__pwritev(int fd, const struct iovec *bufs, size_t nbufs, off_t off) { static _Atomic uintptr_t cache; - return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/0); + return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/ 0); } - -static ssize_t uv__fs_read(uv_fs_t* req) { - const struct iovec* bufs; +static ssize_t uv__fs_read(uv_fs_t *req) { + const struct iovec *bufs; unsigned int iovmax; size_t nbufs; ssize_t r; @@ -519,7 +458,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) { fd = req->file; off = req->off; - bufs = (const struct iovec*) req->bufs; + bufs = (const struct iovec *)req->bufs; nbufs = req->nbufs; iovmax = uv__getiovmax(); @@ -562,19 +501,16 @@ static ssize_t uv__fs_read(uv_fs_t* req) { return r; } - -static int uv__fs_scandir_filter(const uv__dirent_t* dent) { +static int uv__fs_scandir_filter(const uv__dirent_t *dent) { return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0; } - -static int uv__fs_scandir_sort(const uv__dirent_t** a, const uv__dirent_t** b) { +static int uv__fs_scandir_sort(const uv__dirent_t **a, const uv__dirent_t **b) { return strcmp((*a)->d_name, (*b)->d_name); } - -static ssize_t uv__fs_scandir(uv_fs_t* req) { - uv__dirent_t** dents; +static ssize_t uv__fs_scandir(uv_fs_t *req) { + uv__dirent_t **dents; int n; dents = NULL; @@ -598,8 +534,8 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) { return n; } -static int uv__fs_opendir(uv_fs_t* req) { - uv_dir_t* dir; +static int uv__fs_opendir(uv_fs_t *req) { + uv_dir_t *dir; dir = uv__malloc(sizeof(*dir)); if (dir == NULL) @@ -618,10 +554,10 @@ error: return -1; } -static int uv__fs_readdir(uv_fs_t* req) { - uv_dir_t* dir; - uv_dirent_t* dirent; - struct dirent* res; +static int uv__fs_readdir(uv_fs_t *req) { + uv_dir_t *dir; + uv_dirent_t *dirent; + struct dirent *res; unsigned int dirent_idx; unsigned int i; @@ -657,15 +593,15 @@ static int uv__fs_readdir(uv_fs_t* req) { error: for (i = 0; i < dirent_idx; ++i) { - uv__free((char*) dir->dirents[i].name); + uv__free((char *)dir->dirents[i].name); dir->dirents[i].name = NULL; } return -1; } -static int uv__fs_closedir(uv_fs_t* req) { - uv_dir_t* dir; +static int uv__fs_closedir(uv_fs_t *req) { + uv_dir_t *dir; dir = req->ptr; @@ -679,13 +615,10 @@ static int uv__fs_closedir(uv_fs_t* req) { return 0; } -static int uv__fs_statfs(uv_fs_t* req) { - uv_statfs_t* stat_fs; -#if defined(__sun) || \ - defined(__MVS__) || \ - defined(__NetBSD__) || \ - defined(__HAIKU__) || \ - defined(__QNX__) +static int uv__fs_statfs(uv_fs_t *req) { + uv_statfs_t *stat_fs; +#if defined(__sun) || defined(__MVS__) || defined(__NetBSD__) || \ + defined(__HAIKU__) || defined(__QNX__) struct statvfs buf; if (0 != statvfs(req->path, &buf)) @@ -702,13 +635,9 @@ static int uv__fs_statfs(uv_fs_t* req) { return -1; } -#if defined(__sun) || \ - defined(__MVS__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) || \ - defined(__HAIKU__) || \ - defined(__QNX__) - stat_fs->f_type = 0; /* f_type is not supported. */ +#if defined(__sun) || defined(__MVS__) || defined(__OpenBSD__) || \ + defined(__NetBSD__) || defined(__HAIKU__) || defined(__QNX__) + stat_fs->f_type = 0; /* f_type is not supported. */ #else stat_fs->f_type = buf.f_type; #endif @@ -722,7 +651,7 @@ static int uv__fs_statfs(uv_fs_t* req) { return 0; } -static ssize_t uv__fs_pathmax_size(const char* path) { +static ssize_t uv__fs_pathmax_size(const char *path) { ssize_t pathmax; pathmax = pathconf(path, _PC_PATH_MAX); @@ -733,10 +662,10 @@ static ssize_t uv__fs_pathmax_size(const char* path) { return pathmax; } -static ssize_t uv__fs_readlink(uv_fs_t* req) { +static ssize_t uv__fs_readlink(uv_fs_t *req) { ssize_t maxlen; ssize_t len; - char* buf; + char *buf; #if defined(_POSIX_PATH_MAX) || defined(PATH_MAX) maxlen = uv__fs_pathmax_size(req->path); @@ -792,9 +721,9 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) { return 0; } -static ssize_t uv__fs_realpath(uv_fs_t* req) { - char* buf; - char* tmp; +static ssize_t uv__fs_realpath(uv_fs_t *req) { + char *buf; + char *tmp; #if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L tmp = realpath(req->path, NULL); @@ -830,7 +759,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) { return 0; } -static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) { +static ssize_t uv__fs_sendfile_emul(uv_fs_t *req) { struct pollfd pfd; int use_pread; off_t offset; @@ -874,7 +803,7 @@ static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) { * FIXME: There is no way now to signal that we managed to send *some* data * before a write error. */ - for (nsent = 0; (size_t) nsent < len; ) { + for (nsent = 0; (size_t)nsent < len;) { buflen = len - nsent; if (buflen > sizeof(buf)) @@ -902,7 +831,7 @@ static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) { goto out; } - for (nwritten = 0; nwritten < nread; ) { + for (nwritten = 0; nwritten < nread;) { do n = write(out_fd, buf + nwritten, nread - nwritten); while (n == -1 && errno == EINTR); @@ -943,7 +872,6 @@ out: return nsent; } - #ifdef __linux__ /* Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from command * in copy_file_range() when it shouldn't. There is no workaround except to @@ -961,26 +889,24 @@ static int uv__is_buggy_cephfs(int fd) { return uv__kernel_version() < /* 4.20.0 */ 0x041400; } - static int uv__is_cifs_or_smb(int fd) { struct statfs s; if (-1 == fstatfs(fd, &s)) return 0; - switch ((unsigned) s.f_type) { - case 0x0000517Bu: /* SMB */ - case 0xFE534D42u: /* SMB2 */ - case 0xFF534D42u: /* CIFS */ + switch ((unsigned)s.f_type) { + case 0x0000517Bu: /* SMB */ + case 0xFE534D42u: /* SMB2 */ + case 0xFF534D42u: /* CIFS */ return 1; } return 0; } - -static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, - int out_fd, size_t len) { +static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t *off, int out_fd, + size_t len) { static _Atomic int no_copy_file_range_support; ssize_t r; @@ -1000,7 +926,7 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, * copy-from command when it shouldn't. */ if (uv__is_buggy_cephfs(in_fd)) - errno = ENOSYS; /* Use fallback. */ + errno = ENOSYS; /* Use fallback. */ break; case ENOSYS: atomic_store_explicit(&no_copy_file_range_support, 1, memory_order_relaxed); @@ -1010,7 +936,7 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, * Consider it a transient error. */ if (uv__is_cifs_or_smb(out_fd)) - errno = ENOSYS; /* Use fallback. */ + errno = ENOSYS; /* Use fallback. */ break; case ENOTSUP: case EXDEV: @@ -1018,17 +944,16 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, * EXDEV - it will not work when in_fd and out_fd are not on the same * mounted filesystem (pre Linux 5.3) */ - errno = ENOSYS; /* Use fallback. */ + errno = ENOSYS; /* Use fallback. */ break; } return -1; } -#endif /* __linux__ */ +#endif /* __linux__ */ - -static ssize_t uv__fs_sendfile(uv_fs_t* req) { +static ssize_t uv__fs_sendfile(uv_fs_t *req) { int in_fd; int out_fd; @@ -1064,9 +989,7 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { return r; } - if (errno == EINVAL || - errno == EIO || - errno == ENOTSOCK || + if (errno == EINVAL || errno == EIO || errno == ENOTSOCK || errno == EXDEV) { errno = 0; return uv__fs_sendfile_emul(req); @@ -1075,9 +998,8 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { return -1; } /* sendfile() on iOS(arm64) will throw SIGSYS signal cause crash. */ -#elif (defined(__APPLE__) && !TARGET_OS_IPHONE) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) +#elif (defined(__APPLE__) && !TARGET_OS_IPHONE) || defined(__DragonFly__) || \ + defined(__FreeBSD__) { off_t len; ssize_t r; @@ -1092,11 +1014,12 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { off_t off; off = req->off; - r = uv__fs_copy_file_range(in_fd, &off, out_fd, NULL, req->bufsml[0].len, 0); + r = uv__fs_copy_file_range(in_fd, &off, out_fd, NULL, req->bufsml[0].len, + 0); if (r >= 0) { - r = off - req->off; - req->off = off; - return r; + r = off - req->off; + req->off = off; + return r; } #endif len = 0; @@ -1108,7 +1031,7 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { r = sendfile(in_fd, out_fd, req->off, &len, NULL, 0); #endif - /* + /* * The man page for sendfile(2) on DragonFly states that `len` contains * a meaningful value ONLY in case of EAGAIN and EINTR. * Nothing is said about it's value in case of other errors, so better @@ -1117,12 +1040,10 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { */ if (r == 0 || ((errno == EAGAIN || errno == EINTR) && len != 0)) { req->off += len; - return (ssize_t) len; + return (ssize_t)len; } - if (errno == EINVAL || - errno == EIO || - errno == ENOTSOCK || + if (errno == EINVAL || errno == EIO || errno == ENOTSOCK || errno == EXDEV) { errno = 0; return uv__fs_sendfile_emul(req); @@ -1132,25 +1053,18 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { } #else /* Squelch compiler warnings. */ - (void) &in_fd; - (void) &out_fd; + (void)&in_fd; + (void)&out_fd; return uv__fs_sendfile_emul(req); #endif } - -static ssize_t uv__fs_utime(uv_fs_t* req) { -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +static ssize_t uv__fs_utime(uv_fs_t *req) { +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1167,25 +1081,18 @@ static ssize_t uv__fs_utime(uv_fs_t* req) { atr.att_atimechg = 1; atr.att_mtime = req->mtime; atr.att_atime = req->atime; - return __lchattr((char*) req->path, &atr, sizeof(atr)); + return __lchattr((char *)req->path, &atr, sizeof(atr)); #else errno = ENOSYS; return -1; #endif } - -static ssize_t uv__fs_lutime(uv_fs_t* req) { -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +static ssize_t uv__fs_lutime(uv_fs_t *req) { +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1196,9 +1103,8 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) { #endif } - -static ssize_t uv__fs_write(uv_fs_t* req) { - const struct iovec* bufs; +static ssize_t uv__fs_write(uv_fs_t *req) { + const struct iovec *bufs; size_t nbufs; ssize_t r; off_t off; @@ -1206,7 +1112,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) { fd = req->file; off = req->off; - bufs = (const struct iovec*) req->bufs; + bufs = (const struct iovec *)req->bufs; nbufs = req->nbufs; r = 0; @@ -1225,8 +1131,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) { return r; } - -static ssize_t uv__fs_copyfile(uv_fs_t* req) { +static ssize_t uv__fs_copyfile(uv_fs_t *req) { uv_fs_t fs_req; uv_file srcfd; uv_file dstfd; @@ -1263,12 +1168,8 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { dst_flags |= O_EXCL; /* Open the destination file. */ - dstfd = uv_fs_open(NULL, - &fs_req, - req->new_path, - dst_flags, - src_statsbuf.st_mode, - NULL); + dstfd = uv_fs_open(NULL, &fs_req, req->new_path, dst_flags, + src_statsbuf.st_mode, NULL); uv_fs_req_cleanup(&fs_req); if (dstfd < 0) { @@ -1355,7 +1256,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { err = 0; #else /* !__linux__ */ goto out; -#endif /* !__linux__ */ +#endif /* !__linux__ */ } #ifdef FICLONE @@ -1383,7 +1284,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { in_offset = 0; while (bytes_to_send != 0) { bytes_chunk = SSIZE_MAX; - if (bytes_to_send < (off_t) bytes_chunk) + if (bytes_to_send < (off_t)bytes_chunk) bytes_chunk = bytes_to_send; uv_fs_sendfile(NULL, &fs_req, dstfd, srcfd, in_offset, bytes_chunk, NULL); bytes_written = fs_req.result; @@ -1434,7 +1335,7 @@ out: return -1; } -static void uv__to_stat(struct stat* src, uv_stat_t* dst) { +static void uv__to_stat(struct stat *src, uv_stat_t *dst) { dst->st_dev = src->st_dev; dst->st_mode = src->st_mode; dst->st_nlink = src->st_nlink; @@ -1468,35 +1369,28 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) { dst->st_birthtim.tv_nsec = src->st_ctimensec; dst->st_flags = 0; dst->st_gen = 0; -#elif !defined(_AIX) && \ - !defined(__MVS__) && ( \ - defined(__DragonFly__) || \ - defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) || \ - defined(_GNU_SOURCE) || \ - defined(_BSD_SOURCE) || \ - defined(_SVID_SOURCE) || \ - defined(_XOPEN_SOURCE) || \ - defined(_DEFAULT_SOURCE)) +#elif !defined(_AIX) && !defined(__MVS__) && \ + (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ + defined(__NetBSD__) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \ + defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) || \ + defined(_DEFAULT_SOURCE)) dst->st_atim.tv_sec = src->st_atim.tv_sec; dst->st_atim.tv_nsec = src->st_atim.tv_nsec; dst->st_mtim.tv_sec = src->st_mtim.tv_sec; dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec; dst->st_ctim.tv_sec = src->st_ctim.tv_sec; dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec; -# if defined(__FreeBSD__) || \ - defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec; dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec; dst->st_flags = src->st_flags; dst->st_gen = src->st_gen; -# else +#else dst->st_birthtim.tv_sec = src->st_ctim.tv_sec; dst->st_birthtim.tv_nsec = src->st_ctim.tv_nsec; dst->st_flags = 0; dst->st_gen = 0; -# endif +#endif #else dst->st_atim.tv_sec = src->st_atime; dst->st_atim.tv_nsec = 0; @@ -1511,12 +1405,8 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) { #endif } - -static int uv__fs_statx(int fd, - const char* path, - int is_fstat, - int is_lstat, - uv_stat_t* buf) { +static int uv__fs_statx(int fd, const char *path, int is_fstat, int is_lstat, + uv_stat_t *buf) { STATIC_ASSERT(UV_ENOSYS != -1); #ifdef __linux__ static _Atomic int no_statx; @@ -1530,7 +1420,7 @@ static int uv__fs_statx(int fd, return UV_ENOSYS; dirfd = AT_FDCWD; - flags = 0; /* AT_STATX_SYNC_AS_STAT */ + flags = 0; /* AT_STATX_SYNC_AS_STAT */ mode = 0xFFF; /* STATX_BASIC_STATS + STATX_BTIME */ if (is_fstat) { @@ -1551,7 +1441,8 @@ static int uv__fs_statx(int fd, * Has been observed with libseccomp < 2.3.3 and docker < 18.04. * EOPNOTSUPP is used on DVS exported filesystems */ - if (errno != EINVAL && errno != EPERM && errno != ENOSYS && errno != EOPNOTSUPP) + if (errno != EINVAL && errno != EPERM && errno != ENOSYS && + errno != EOPNOTSUPP) return -1; /* Fall through. */ default: @@ -1572,7 +1463,6 @@ static int uv__fs_statx(int fd, #endif /* __linux__ */ } - static int uv__fs_stat(const char *path, uv_stat_t *buf) { struct stat pbuf; int ret; @@ -1588,7 +1478,6 @@ static int uv__fs_stat(const char *path, uv_stat_t *buf) { return ret; } - static int uv__fs_lstat(const char *path, uv_stat_t *buf) { struct stat pbuf; int ret; @@ -1604,7 +1493,6 @@ static int uv__fs_lstat(const char *path, uv_stat_t *buf) { return ret; } - static int uv__fs_fstat(int fd, uv_stat_t *buf) { struct stat pbuf; int ret; @@ -1620,7 +1508,7 @@ static int uv__fs_fstat(int fd, uv_stat_t *buf) { return ret; } -static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) { +static size_t uv__fs_buf_offset(uv_buf_t *bufs, size_t size) { size_t offset; /* Figure out which bufs are done */ for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset) @@ -1634,10 +1522,10 @@ static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) { return offset; } -static ssize_t uv__fs_write_all(uv_fs_t* req) { +static ssize_t uv__fs_write_all(uv_fs_t *req) { unsigned int iovmax; unsigned int nbufs; - uv_buf_t* bufs; + uv_buf_t *bufs; ssize_t total; ssize_t result; @@ -1679,62 +1567,61 @@ static ssize_t uv__fs_write_all(uv_fs_t* req) { return total; } - -static void uv__fs_work(struct uv__work* w) { +static void uv__fs_work(struct uv__work *w) { int retry_on_eintr; - uv_fs_t* req; + uv_fs_t *req; ssize_t r; req = container_of(w, uv_fs_t, work_req); - retry_on_eintr = !(req->fs_type == UV_FS_CLOSE || - req->fs_type == UV_FS_READ); + retry_on_eintr = !(req->fs_type == UV_FS_CLOSE || req->fs_type == UV_FS_READ); do { errno = 0; -#define X(type, action) \ - case UV_FS_ ## type: \ - r = action; \ +#define X(type, action) \ + case UV_FS_##type: \ + r = action; \ break; switch (req->fs_type) { - X(ACCESS, access(req->path, req->flags)); - X(CHMOD, chmod(req->path, req->mode)); - X(CHOWN, chown(req->path, req->uid, req->gid)); - X(CLOSE, uv__fs_close(req->file)); - X(COPYFILE, uv__fs_copyfile(req)); - X(FCHMOD, fchmod(req->file, req->mode)); - X(FCHOWN, fchown(req->file, req->uid, req->gid)); - X(LCHOWN, lchown(req->path, req->uid, req->gid)); - X(FDATASYNC, uv__fs_fdatasync(req)); - X(FSTAT, uv__fs_fstat(req->file, &req->statbuf)); - X(FSYNC, uv__fs_fsync(req)); - X(FTRUNCATE, ftruncate(req->file, req->off)); - X(FUTIME, uv__fs_futime(req)); - X(LUTIME, uv__fs_lutime(req)); - X(LSTAT, uv__fs_lstat(req->path, &req->statbuf)); - X(LINK, link(req->path, req->new_path)); - X(MKDIR, mkdir(req->path, req->mode)); - X(MKDTEMP, uv__fs_mkdtemp(req)); - X(MKSTEMP, uv__fs_mkstemp(req)); - X(OPEN, uv__fs_open(req)); - X(READ, uv__fs_read(req)); - X(SCANDIR, uv__fs_scandir(req)); - X(OPENDIR, uv__fs_opendir(req)); - X(READDIR, uv__fs_readdir(req)); - X(CLOSEDIR, uv__fs_closedir(req)); - X(READLINK, uv__fs_readlink(req)); - X(REALPATH, uv__fs_realpath(req)); - X(RENAME, rename(req->path, req->new_path)); - X(RMDIR, rmdir(req->path)); - X(SENDFILE, uv__fs_sendfile(req)); - X(STAT, uv__fs_stat(req->path, &req->statbuf)); - X(STATFS, uv__fs_statfs(req)); - X(SYMLINK, symlink(req->path, req->new_path)); - X(UNLINK, unlink(req->path)); - X(UTIME, uv__fs_utime(req)); - X(WRITE, uv__fs_write_all(req)); - default: abort(); + X(ACCESS, access(req->path, req->flags)); + X(CHMOD, chmod(req->path, req->mode)); + X(CHOWN, chown(req->path, req->uid, req->gid)); + X(CLOSE, uv__fs_close(req->file)); + X(COPYFILE, uv__fs_copyfile(req)); + X(FCHMOD, fchmod(req->file, req->mode)); + X(FCHOWN, fchown(req->file, req->uid, req->gid)); + X(LCHOWN, lchown(req->path, req->uid, req->gid)); + X(FDATASYNC, uv__fs_fdatasync(req)); + X(FSTAT, uv__fs_fstat(req->file, &req->statbuf)); + X(FSYNC, uv__fs_fsync(req)); + X(FTRUNCATE, ftruncate(req->file, req->off)); + X(FUTIME, uv__fs_futime(req)); + X(LUTIME, uv__fs_lutime(req)); + X(LSTAT, uv__fs_lstat(req->path, &req->statbuf)); + X(LINK, link(req->path, req->new_path)); + X(MKDIR, mkdir(req->path, req->mode)); + X(MKDTEMP, uv__fs_mkdtemp(req)); + X(MKSTEMP, uv__fs_mkstemp(req)); + X(OPEN, uv__fs_open(req)); + X(READ, uv__fs_read(req)); + X(SCANDIR, uv__fs_scandir(req)); + X(OPENDIR, uv__fs_opendir(req)); + X(READDIR, uv__fs_readdir(req)); + X(CLOSEDIR, uv__fs_closedir(req)); + X(READLINK, uv__fs_readlink(req)); + X(REALPATH, uv__fs_realpath(req)); + X(RENAME, rename(req->path, req->new_path)); + X(RMDIR, rmdir(req->path)); + X(SENDFILE, uv__fs_sendfile(req)); + X(STAT, uv__fs_stat(req->path, &req->statbuf)); + X(STATFS, uv__fs_statfs(req)); + X(SYMLINK, symlink(req->path, req->new_path)); + X(UNLINK, unlink(req->path)); + X(UTIME, uv__fs_utime(req)); + X(WRITE, uv__fs_write_all(req)); + default: + abort(); } #undef X } while (r == -1 && errno == EINTR && retry_on_eintr); @@ -1744,16 +1631,14 @@ static void uv__fs_work(struct uv__work* w) { else req->result = r; - if (r == 0 && (req->fs_type == UV_FS_STAT || - req->fs_type == UV_FS_FSTAT || + if (r == 0 && (req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_FSTAT || req->fs_type == UV_FS_LSTAT)) { req->ptr = &req->statbuf; } } - -static void uv__fs_done(struct uv__work* w, int status) { - uv_fs_t* req; +static void uv__fs_done(struct uv__work *w, int status) { + uv_fs_t *req; req = container_of(w, uv_fs_t, work_req); uv__req_unregister(req->loop); @@ -1766,21 +1651,13 @@ static void uv__fs_done(struct uv__work* w, int status) { req->cb(req); } - -void uv__fs_post(uv_loop_t* loop, uv_fs_t* req) { +void uv__fs_post(uv_loop_t *loop, uv_fs_t *req) { uv__req_register(loop); - uv__work_submit(loop, - &req->work_req, - UV__WORK_FAST_IO, - uv__fs_work, + uv__work_submit(loop, &req->work_req, UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); } - -int uv_fs_access(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int flags, +int uv_fs_access(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) { INIT(ACCESS); PATH; @@ -1788,11 +1665,7 @@ int uv_fs_access(uv_loop_t* loop, POST; } - -int uv_fs_chmod(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int mode, +int uv_fs_chmod(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb) { INIT(CHMOD); PATH; @@ -1800,13 +1673,8 @@ int uv_fs_chmod(uv_loop_t* loop, POST; } - -int uv_fs_chown(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - uv_uid_t uid, - uv_gid_t gid, - uv_fs_cb cb) { +int uv_fs_chown(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_uid_t uid, + uv_gid_t gid, uv_fs_cb cb) { INIT(CHOWN); PATH; req->uid = uid; @@ -1814,8 +1682,7 @@ int uv_fs_chown(uv_loop_t* loop, POST; } - -int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(CLOSE); req->file = file; if (cb != NULL) @@ -1824,11 +1691,7 @@ int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_fchmod(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - int mode, +int uv_fs_fchmod(uv_loop_t *loop, uv_fs_t *req, uv_file file, int mode, uv_fs_cb cb) { INIT(FCHMOD); req->file = file; @@ -1836,13 +1699,8 @@ int uv_fs_fchmod(uv_loop_t* loop, POST; } - -int uv_fs_fchown(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - uv_uid_t uid, - uv_gid_t gid, - uv_fs_cb cb) { +int uv_fs_fchown(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_uid_t uid, + uv_gid_t gid, uv_fs_cb cb) { INIT(FCHOWN); req->file = file; req->uid = uid; @@ -1850,13 +1708,8 @@ int uv_fs_fchown(uv_loop_t* loop, POST; } - -int uv_fs_lchown(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - uv_uid_t uid, - uv_gid_t gid, - uv_fs_cb cb) { +int uv_fs_lchown(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_uid_t uid, + uv_gid_t gid, uv_fs_cb cb) { INIT(LCHOWN); PATH; req->uid = uid; @@ -1864,8 +1717,7 @@ int uv_fs_lchown(uv_loop_t* loop, POST; } - -int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fdatasync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(FDATASYNC); req->file = file; if (cb != NULL) @@ -1874,8 +1726,7 @@ int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fstat(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(FSTAT); req->file = file; if (cb != NULL) @@ -1884,8 +1735,7 @@ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fsync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(FSYNC); req->file = file; if (cb != NULL) @@ -1894,11 +1744,7 @@ int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_ftruncate(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - int64_t off, +int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file file, int64_t off, uv_fs_cb cb) { INIT(FTRUNCATE); req->file = file; @@ -1909,13 +1755,8 @@ int uv_fs_ftruncate(uv_loop_t* loop, POST; } - -int uv_fs_futime(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - double atime, - double mtime, - uv_fs_cb cb) { +int uv_fs_futime(uv_loop_t *loop, uv_fs_t *req, uv_file file, double atime, + double mtime, uv_fs_cb cb) { INIT(FUTIME); req->file = file; req->atime = atime; @@ -1923,12 +1764,8 @@ int uv_fs_futime(uv_loop_t* loop, POST; } -int uv_fs_lutime(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - double atime, - double mtime, - uv_fs_cb cb) { +int uv_fs_lutime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, + double mtime, uv_fs_cb cb) { INIT(LUTIME); PATH; req->atime = atime; @@ -1936,8 +1773,7 @@ int uv_fs_lutime(uv_loop_t* loop, POST; } - -int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_lstat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(LSTAT); PATH; if (cb != NULL) @@ -1946,12 +1782,8 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_link(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - const char* new_path, - uv_fs_cb cb) { +int uv_fs_link(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, uv_fs_cb cb) { INIT(LINK); PATH2; if (cb != NULL) @@ -1960,11 +1792,7 @@ int uv_fs_link(uv_loop_t* loop, POST; } - -int uv_fs_mkdir(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int mode, +int uv_fs_mkdir(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb) { INIT(MKDIR); PATH; @@ -1975,11 +1803,7 @@ int uv_fs_mkdir(uv_loop_t* loop, POST; } - -int uv_fs_mkdtemp(uv_loop_t* loop, - uv_fs_t* req, - const char* tpl, - uv_fs_cb cb) { +int uv_fs_mkdtemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) { INIT(MKDTEMP); req->path = uv__strdup(tpl); if (req->path == NULL) @@ -1987,11 +1811,7 @@ int uv_fs_mkdtemp(uv_loop_t* loop, POST; } - -int uv_fs_mkstemp(uv_loop_t* loop, - uv_fs_t* req, - const char* tpl, - uv_fs_cb cb) { +int uv_fs_mkstemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) { INIT(MKSTEMP); req->path = uv__strdup(tpl); if (req->path == NULL) @@ -1999,13 +1819,8 @@ int uv_fs_mkstemp(uv_loop_t* loop, POST; } - -int uv_fs_open(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int flags, - int mode, - uv_fs_cb cb) { +int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, + int mode, uv_fs_cb cb) { INIT(OPEN); PATH; req->flags = flags; @@ -2016,12 +1831,8 @@ int uv_fs_open(uv_loop_t* loop, POST; } - -int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, - uv_file file, - const uv_buf_t bufs[], - unsigned int nbufs, - int64_t off, +int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, + const uv_buf_t bufs[], unsigned int nbufs, int64_t off, uv_fs_cb cb) { INIT(READ); @@ -2030,7 +1841,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, req->off = off; req->file = file; - req->bufs = (uv_buf_t*) bufs; /* Safe, doesn't mutate |bufs| */ + req->bufs = (uv_buf_t *)bufs; /* Safe, doesn't mutate |bufs| */ req->nbufs = nbufs; if (cb == NULL) @@ -2052,11 +1863,7 @@ post: POST; } - -int uv_fs_scandir(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int flags, +int uv_fs_scandir(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) { INIT(SCANDIR); PATH; @@ -2064,19 +1871,14 @@ int uv_fs_scandir(uv_loop_t* loop, POST; } -int uv_fs_opendir(uv_loop_t* loop, - uv_fs_t* req, - const char* path, +int uv_fs_opendir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(OPENDIR); PATH; POST; } -int uv_fs_readdir(uv_loop_t* loop, - uv_fs_t* req, - uv_dir_t* dir, - uv_fs_cb cb) { +int uv_fs_readdir(uv_loop_t *loop, uv_fs_t *req, uv_dir_t *dir, uv_fs_cb cb) { INIT(READDIR); if (dir == NULL || dir->dir == NULL || dir->dirents == NULL) @@ -2086,10 +1888,7 @@ int uv_fs_readdir(uv_loop_t* loop, POST; } -int uv_fs_closedir(uv_loop_t* loop, - uv_fs_t* req, - uv_dir_t* dir, - uv_fs_cb cb) { +int uv_fs_closedir(uv_loop_t *loop, uv_fs_t *req, uv_dir_t *dir, uv_fs_cb cb) { INIT(CLOSEDIR); if (dir == NULL) @@ -2099,31 +1898,22 @@ int uv_fs_closedir(uv_loop_t* loop, POST; } -int uv_fs_readlink(uv_loop_t* loop, - uv_fs_t* req, - const char* path, +int uv_fs_readlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(READLINK); PATH; POST; } - -int uv_fs_realpath(uv_loop_t* loop, - uv_fs_t* req, - const char * path, - uv_fs_cb cb) { +int uv_fs_realpath(uv_loop_t *loop, uv_fs_t *req, const char *path, + uv_fs_cb cb) { INIT(REALPATH); PATH; POST; } - -int uv_fs_rename(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - const char* new_path, - uv_fs_cb cb) { +int uv_fs_rename(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, uv_fs_cb cb) { INIT(RENAME); PATH2; if (cb != NULL) @@ -2132,21 +1922,14 @@ int uv_fs_rename(uv_loop_t* loop, POST; } - -int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(RMDIR); PATH; POST; } - -int uv_fs_sendfile(uv_loop_t* loop, - uv_fs_t* req, - uv_file out_fd, - uv_file in_fd, - int64_t off, - size_t len, - uv_fs_cb cb) { +int uv_fs_sendfile(uv_loop_t *loop, uv_fs_t *req, uv_file out_fd, uv_file in_fd, + int64_t off, size_t len, uv_fs_cb cb) { INIT(SENDFILE); req->flags = in_fd; /* hack */ req->file = out_fd; @@ -2155,8 +1938,7 @@ int uv_fs_sendfile(uv_loop_t* loop, POST; } - -int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_stat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(STAT); PATH; if (cb != NULL) @@ -2165,13 +1947,8 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_symlink(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - const char* new_path, - int flags, - uv_fs_cb cb) { +int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, int flags, uv_fs_cb cb) { INIT(SYMLINK); PATH2; req->flags = flags; @@ -2181,8 +1958,7 @@ int uv_fs_symlink(uv_loop_t* loop, POST; } - -int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(UNLINK); PATH; if (cb != NULL) @@ -2191,13 +1967,8 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_utime(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - double atime, - double mtime, - uv_fs_cb cb) { +int uv_fs_utime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, + double mtime, uv_fs_cb cb) { INIT(UTIME); PATH; req->atime = atime; @@ -2205,13 +1976,8 @@ int uv_fs_utime(uv_loop_t* loop, POST; } - -int uv_fs_write(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - const uv_buf_t bufs[], - unsigned int nbufs, - int64_t off, +int uv_fs_write(uv_loop_t *loop, uv_fs_t *req, uv_file file, + const uv_buf_t bufs[], unsigned int nbufs, int64_t off, uv_fs_cb cb) { INIT(WRITE); @@ -2239,8 +2005,7 @@ int uv_fs_write(uv_loop_t* loop, POST; } - -void uv_fs_req_cleanup(uv_fs_t* req) { +void uv_fs_req_cleanup(uv_fs_t *req) { if (req == NULL) return; @@ -2249,10 +2014,9 @@ void uv_fs_req_cleanup(uv_fs_t* req) { * req->new_path pointing to user-owned memory. UV_FS_MKDTEMP and * UV_FS_MKSTEMP are the exception to the rule, they always allocate memory. */ - if (req->path != NULL && - (req->cb != NULL || - req->fs_type == UV_FS_MKDTEMP || req->fs_type == UV_FS_MKSTEMP)) - uv__free((void*) req->path); /* Memory is shared with req->new_path. */ + if (req->path != NULL && (req->cb != NULL || req->fs_type == UV_FS_MKDTEMP || + req->fs_type == UV_FS_MKSTEMP)) + uv__free((void *)req->path); /* Memory is shared with req->new_path. */ req->path = NULL; req->new_path = NULL; @@ -2272,17 +2036,11 @@ void uv_fs_req_cleanup(uv_fs_t* req) { req->ptr = NULL; } - -int uv_fs_copyfile(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - const char* new_path, - int flags, - uv_fs_cb cb) { +int uv_fs_copyfile(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, int flags, uv_fs_cb cb) { INIT(COPYFILE); - if (flags & ~(UV_FS_COPYFILE_EXCL | - UV_FS_COPYFILE_FICLONE | + if (flags & ~(UV_FS_COPYFILE_EXCL | UV_FS_COPYFILE_FICLONE | UV_FS_COPYFILE_FICLONE_FORCE)) { return UV_EINVAL; } @@ -2292,16 +2050,10 @@ int uv_fs_copyfile(uv_loop_t* loop, POST; } - -int uv_fs_statfs(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - uv_fs_cb cb) { +int uv_fs_statfs(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(STATFS); PATH; POST; } -int uv_fs_get_system_error(const uv_fs_t* req) { - return -req->result; -} +int uv_fs_get_system_error(const uv_fs_t *req) { return -req->result; } diff --git a/test/test-fs.c b/test/test-fs.c index 4ce059c39..28559c224 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -19,41 +19,41 @@ * IN THE SOFTWARE. */ -#include "uv.h" #include "task.h" +#include "uv.h" #include -#include /* memset */ #include -#include #include /* INT_MAX, PATH_MAX, IOV_MAX */ +#include /* memset */ +#include #ifndef _WIN32 -# include /* unlink, rmdir, etc. */ +#include /* unlink, rmdir, etc. */ #else -# include -# include -# include -# ifndef ERROR_SYMLINK_NOT_SUPPORTED -# define ERROR_SYMLINK_NOT_SUPPORTED 1464 -# endif -# ifndef S_IFIFO -# define S_IFIFO _S_IFIFO -# endif -# define unlink _unlink -# define rmdir _rmdir -# define open _open -# define write _write -# define close _close -# ifndef stat -# define stat _stati64 -# endif -# ifndef lseek -# define lseek _lseek -# endif -# define S_IFDIR _S_IFDIR -# define S_IFCHR _S_IFCHR -# define S_IFREG _S_IFREG +#include +#include +#include +#ifndef ERROR_SYMLINK_NOT_SUPPORTED +#define ERROR_SYMLINK_NOT_SUPPORTED 1464 +#endif +#ifndef S_IFIFO +#define S_IFIFO _S_IFIFO +#endif +#define unlink _unlink +#define rmdir _rmdir +#define open _open +#define write _write +#define close _close +#ifndef stat +#define stat _stati64 +#endif +#ifndef lseek +#define lseek _lseek +#endif +#define S_IFDIR _S_IFDIR +#define S_IFCHR _S_IFCHR +#define S_IFREG _S_IFREG #endif #define TOO_LONG_NAME_LENGTH 65536 @@ -72,12 +72,11 @@ static const int is_apple_or_sunpro_c = 0; #endif typedef struct { - const char* path; + const char *path; double atime; double mtime; } utime_check_t; - static int dummy_cb_count; static int close_cb_count; static int create_cb_count; @@ -112,7 +111,7 @@ static int futime_cb_count; static int lutime_cb_count; static int statfs_cb_count; -static uv_loop_t* loop; +static uv_loop_t *loop; static uv_fs_t open_req1; static uv_fs_t open_req2; @@ -160,7 +159,8 @@ int uv_test_getiovmax(void) { * sysconf(_SC_IOV_MAX) can not get the correct value. The return * value is -1 and the errno is EINPROGRESS. Degrade the value to 1. */ - if (iovmax == -1) iovmax = 1; + if (iovmax == -1) + iovmax = 1; } return iovmax; #else @@ -173,17 +173,18 @@ int uv_test_getiovmax(void) { /* * This tag and guid have no special meaning, and don't conflict with * reserved ids. -*/ + */ static unsigned REPARSE_TAG = 0x9913; -static GUID REPARSE_GUID = { - 0x1bf6205f, 0x46ae, 0x4527, - { 0xb1, 0x0c, 0xc5, 0x09, 0xb7, 0x55, 0x22, 0x80 }}; +static GUID REPARSE_GUID = {0x1bf6205f, + 0x46ae, + 0x4527, + {0xb1, 0x0c, 0xc5, 0x09, 0xb7, 0x55, 0x22, 0x80}}; #endif -static void check_permission(const char* filename, unsigned int mode) { +static void check_permission(const char *filename, unsigned int mode) { int r; uv_fs_t req; - uv_stat_t* s; + uv_stat_t *s; r = uv_fs_stat(NULL, &req, filename, NULL); ASSERT_OK(r); @@ -203,29 +204,26 @@ static void check_permission(const char* filename, unsigned int mode) { uv_fs_req_cleanup(&req); } - -static void dummy_cb(uv_fs_t* req) { - (void) req; +static void dummy_cb(uv_fs_t *req) { + (void)req; dummy_cb_count++; } - -static void link_cb(uv_fs_t* req) { +static void link_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_LINK); ASSERT_OK(req->result); link_cb_count++; uv_fs_req_cleanup(req); } - -static void symlink_cb(uv_fs_t* req) { +static void symlink_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_SYMLINK); ASSERT_OK(req->result); symlink_cb_count++; uv_fs_req_cleanup(req); } -static void readlink_cb(uv_fs_t* req) { +static void readlink_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_READLINK); ASSERT_OK(req->result); ASSERT_OK(strcmp(req->ptr, "test_file_symlink2")); @@ -233,8 +231,7 @@ static void readlink_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } - -static void realpath_cb(uv_fs_t* req) { +static void realpath_cb(uv_fs_t *req) { char test_file_abs_buf[PATHMAX]; size_t test_file_abs_size = sizeof(test_file_abs_buf); ASSERT_EQ(req->fs_type, UV_FS_REALPATH); @@ -252,55 +249,50 @@ static void realpath_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } - -static void access_cb(uv_fs_t* req) { +static void access_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_ACCESS); access_cb_count++; uv_fs_req_cleanup(req); } - -static void fchmod_cb(uv_fs_t* req) { +static void fchmod_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_FCHMOD); ASSERT_OK(req->result); fchmod_cb_count++; uv_fs_req_cleanup(req); - check_permission("test_file", *(int*)req->data); + check_permission("test_file", *(int *)req->data); } - -static void chmod_cb(uv_fs_t* req) { +static void chmod_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_CHMOD); ASSERT_OK(req->result); chmod_cb_count++; uv_fs_req_cleanup(req); - check_permission("test_file", *(int*)req->data); + check_permission("test_file", *(int *)req->data); } - -static void fchown_cb(uv_fs_t* req) { +static void fchown_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_FCHOWN); ASSERT_OK(req->result); fchown_cb_count++; uv_fs_req_cleanup(req); } - -static void chown_cb(uv_fs_t* req) { +static void chown_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_CHOWN); ASSERT_OK(req->result); chown_cb_count++; uv_fs_req_cleanup(req); } -static void lchown_cb(uv_fs_t* req) { +static void lchown_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_LCHOWN); ASSERT_OK(req->result); lchown_cb_count++; uv_fs_req_cleanup(req); } -static void chown_root_cb(uv_fs_t* req) { +static void chown_root_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_CHOWN); #if defined(_WIN32) || defined(__MSYS__) /* On windows, chown is a no-op and always succeeds. */ @@ -312,24 +304,24 @@ static void chown_root_cb(uv_fs_t* req) { if (geteuid() == 0) ASSERT_OK(req->result); else -# if defined(__CYGWIN__) +#if defined(__CYGWIN__) /* On Cygwin, uid 0 is invalid (no root). */ ASSERT_EQ(req->result, UV_EINVAL); -# elif defined(__PASE__) +#elif defined(__PASE__) /* On IBMi PASE, there is no root user. uid 0 is user qsecofr. * User may grant qsecofr's privileges, including changing * the file's ownership to uid 0. */ ASSERT(req->result == 0 || req->result == UV_EPERM); -# else +#else ASSERT_EQ(req->result, UV_EPERM); -# endif +#endif #endif chown_cb_count++; uv_fs_req_cleanup(req); } -static void unlink_cb(uv_fs_t* req) { +static void unlink_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &unlink_req); ASSERT_EQ(req->fs_type, UV_FS_UNLINK); ASSERT_OK(req->result); @@ -337,8 +329,8 @@ static void unlink_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } -static void fstat_cb(uv_fs_t* req) { - uv_stat_t* s = req->ptr; +static void fstat_cb(uv_fs_t *req) { + uv_stat_t *s = req->ptr; ASSERT_EQ(req->fs_type, UV_FS_FSTAT); ASSERT_OK(req->result); ASSERT_EQ(s->st_size, sizeof(test_buf)); @@ -346,17 +338,16 @@ static void fstat_cb(uv_fs_t* req) { fstat_cb_count++; } - -static void statfs_cb(uv_fs_t* req) { - uv_statfs_t* stats; +static void statfs_cb(uv_fs_t *req) { + uv_statfs_t *stats; ASSERT_EQ(req->fs_type, UV_FS_STATFS); ASSERT_OK(req->result); ASSERT_NOT_NULL(req->ptr); stats = req->ptr; -#if defined(_WIN32) || defined(__sun) || defined(_AIX) || defined(__MVS__) || \ - defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) +#if defined(_WIN32) || defined(__sun) || defined(_AIX) || defined(__MVS__) || \ + defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) ASSERT_OK(stats->f_type); #else ASSERT_UINT64_GT(stats->f_type, 0); @@ -379,8 +370,7 @@ static void statfs_cb(uv_fs_t* req) { statfs_cb_count++; } - -static void close_cb(uv_fs_t* req) { +static void close_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &close_req); ASSERT_EQ(req->fs_type, UV_FS_CLOSE); @@ -393,8 +383,7 @@ static void close_cb(uv_fs_t* req) { } } - -static void ftruncate_cb(uv_fs_t* req) { +static void ftruncate_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &ftruncate_req); ASSERT_EQ(req->fs_type, UV_FS_FTRUNCATE); @@ -405,21 +394,21 @@ static void ftruncate_cb(uv_fs_t* req) { ASSERT_OK(r); } -static void fail_cb(uv_fs_t* req) { +static void fail_cb(uv_fs_t *req) { FATAL("fail_cb should not have been called"); } -static void read_cb(uv_fs_t* req) { +static void read_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &read_req); ASSERT_EQ(req->fs_type, UV_FS_READ); - ASSERT_GE(req->result, 0); /* FIXME(bnoordhuis) Check if requested size? */ + ASSERT_GE(req->result, 0); /* FIXME(bnoordhuis) Check if requested size? */ read_cb_count++; uv_fs_req_cleanup(req); if (read_cb_count == 1) { ASSERT_OK(strcmp(buf, test_buf)); r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, - ftruncate_cb); + ftruncate_cb); } else { ASSERT_OK(strcmp(buf, "test-bu")); r = uv_fs_close(loop, &close_req, open_req1.result, close_cb); @@ -427,13 +416,12 @@ static void read_cb(uv_fs_t* req) { ASSERT_OK(r); } - -static void open_cb(uv_fs_t* req) { +static void open_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &open_req1); ASSERT_EQ(req->fs_type, UV_FS_OPEN); if (req->result < 0) { - fprintf(stderr, "async open error: %d\n", (int) req->result); + fprintf(stderr, "async open error: %d\n", (int)req->result); ASSERT(0); } open_cb_count++; @@ -442,16 +430,14 @@ static void open_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); memset(buf, 0, sizeof(buf)); iov = uv_buf_init(buf, sizeof(buf)); - r = uv_fs_read(loop, &read_req, open_req1.result, &iov, 1, -1, - read_cb); + r = uv_fs_read(loop, &read_req, open_req1.result, &iov, 1, -1, read_cb); ASSERT_OK(r); } - -static void open_cb_simple(uv_fs_t* req) { +static void open_cb_simple(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_OPEN); if (req->result < 0) { - fprintf(stderr, "async open error: %d\n", (int) req->result); + fprintf(stderr, "async open error: %d\n", (int)req->result); ASSERT(0); } open_cb_count++; @@ -459,8 +445,7 @@ static void open_cb_simple(uv_fs_t* req) { uv_fs_req_cleanup(req); } - -static void fsync_cb(uv_fs_t* req) { +static void fsync_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &fsync_req); ASSERT_EQ(req->fs_type, UV_FS_FSYNC); @@ -471,8 +456,7 @@ static void fsync_cb(uv_fs_t* req) { ASSERT_OK(r); } - -static void fdatasync_cb(uv_fs_t* req) { +static void fdatasync_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &fdatasync_req); ASSERT_EQ(req->fs_type, UV_FS_FDATASYNC); @@ -483,20 +467,18 @@ static void fdatasync_cb(uv_fs_t* req) { ASSERT_OK(r); } - -static void write_cb(uv_fs_t* req) { +static void write_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &write_req); ASSERT_EQ(req->fs_type, UV_FS_WRITE); - ASSERT_GE(req->result, 0); /* FIXME(bnoordhuis) Check if requested size? */ + ASSERT_GE(req->result, 0); /* FIXME(bnoordhuis) Check if requested size? */ write_cb_count++; uv_fs_req_cleanup(req); r = uv_fs_fdatasync(loop, &fdatasync_req, open_req1.result, fdatasync_cb); ASSERT_OK(r); } - -static void create_cb(uv_fs_t* req) { +static void create_cb(uv_fs_t *req) { int r; ASSERT_PTR_EQ(req, &open_req1); ASSERT_EQ(req->fs_type, UV_FS_OPEN); @@ -508,8 +490,7 @@ static void create_cb(uv_fs_t* req) { ASSERT_OK(r); } - -static void rename_cb(uv_fs_t* req) { +static void rename_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &rename_req); ASSERT_EQ(req->fs_type, UV_FS_RENAME); ASSERT_OK(req->result); @@ -517,8 +498,7 @@ static void rename_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } - -static void mkdir_cb(uv_fs_t* req) { +static void mkdir_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &mkdir_req); ASSERT_EQ(req->fs_type, UV_FS_MKDIR); ASSERT_OK(req->result); @@ -528,8 +508,7 @@ static void mkdir_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } - -static void check_mkdtemp_result(uv_fs_t* req) { +static void check_mkdtemp_result(uv_fs_t *req) { int r; ASSERT_EQ(req->fs_type, UV_FS_MKDTEMP); @@ -543,19 +522,17 @@ static void check_mkdtemp_result(uv_fs_t* req) { /* Check if req->path is actually a directory */ r = uv_fs_stat(NULL, &stat_req, req->path, NULL); ASSERT_OK(r); - ASSERT(((uv_stat_t*)stat_req.ptr)->st_mode & S_IFDIR); + ASSERT(((uv_stat_t *)stat_req.ptr)->st_mode & S_IFDIR); uv_fs_req_cleanup(&stat_req); } - -static void mkdtemp_cb(uv_fs_t* req) { +static void mkdtemp_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &mkdtemp_req1); check_mkdtemp_result(req); mkdtemp_cb_count++; } - -static void check_mkstemp_result(uv_fs_t* req) { +static void check_mkstemp_result(uv_fs_t *req) { int r; ASSERT_EQ(req->fs_type, UV_FS_MKSTEMP); @@ -573,15 +550,13 @@ static void check_mkstemp_result(uv_fs_t* req) { uv_fs_req_cleanup(&stat_req); } - -static void mkstemp_cb(uv_fs_t* req) { +static void mkstemp_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &mkstemp_req1); check_mkstemp_result(req); mkstemp_cb_count++; } - -static void rmdir_cb(uv_fs_t* req) { +static void rmdir_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &rmdir_req); ASSERT_EQ(req->fs_type, UV_FS_RMDIR); ASSERT_OK(req->result); @@ -591,30 +566,28 @@ static void rmdir_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } - static void assert_is_file_type(uv_dirent_t dent) { #ifdef HAVE_DIRENT_TYPES - /* - * For Apple and Windows, we know getdents is expected to work but for other - * environments, the filesystem dictates whether or not getdents supports - * returning the file type. - * - * See: - * http://man7.org/linux/man-pages/man2/getdents.2.html - * https://github.com/libuv/libuv/issues/501 - */ - #if defined(__APPLE__) || defined(_WIN32) - ASSERT_EQ(dent.type, UV_DIRENT_FILE); - #else - ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN); - #endif +/* + * For Apple and Windows, we know getdents is expected to work but for other + * environments, the filesystem dictates whether or not getdents supports + * returning the file type. + * + * See: + * http://man7.org/linux/man-pages/man2/getdents.2.html + * https://github.com/libuv/libuv/issues/501 + */ +#if defined(__APPLE__) || defined(_WIN32) + ASSERT_EQ(dent.type, UV_DIRENT_FILE); +#else + ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN); +#endif #else ASSERT_EQ(dent.type, UV_DIRENT_UNKNOWN); #endif } - -static void scandir_cb(uv_fs_t* req) { +static void scandir_cb(uv_fs_t *req) { uv_dirent_t dent; ASSERT_PTR_EQ(req, &scandir_req); ASSERT_EQ(req->fs_type, UV_FS_SCANDIR); @@ -632,8 +605,7 @@ static void scandir_cb(uv_fs_t* req) { ASSERT(!req->ptr); } - -static void empty_scandir_cb(uv_fs_t* req) { +static void empty_scandir_cb(uv_fs_t *req) { uv_dirent_t dent; ASSERT_PTR_EQ(req, &scandir_req); @@ -645,7 +617,7 @@ static void empty_scandir_cb(uv_fs_t* req) { scandir_cb_count++; } -static void non_existent_scandir_cb(uv_fs_t* req) { +static void non_existent_scandir_cb(uv_fs_t *req) { uv_dirent_t dent; ASSERT_PTR_EQ(req, &scandir_req); @@ -657,8 +629,7 @@ static void non_existent_scandir_cb(uv_fs_t* req) { scandir_cb_count++; } - -static void file_scandir_cb(uv_fs_t* req) { +static void file_scandir_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &scandir_req); ASSERT_EQ(req->fs_type, UV_FS_SCANDIR); ASSERT_EQ(req->result, UV_ENOTDIR); @@ -667,8 +638,7 @@ static void file_scandir_cb(uv_fs_t* req) { scandir_cb_count++; } - -static void stat_cb(uv_fs_t* req) { +static void stat_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &stat_req); ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT); ASSERT_OK(req->result); @@ -678,7 +648,7 @@ static void stat_cb(uv_fs_t* req) { ASSERT(!req->ptr); } -static void stat_batch_cb(uv_fs_t* req) { +static void stat_batch_cb(uv_fs_t *req) { ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT); ASSERT_OK(req->result); ASSERT(req->ptr); @@ -687,8 +657,7 @@ static void stat_batch_cb(uv_fs_t* req) { ASSERT(!req->ptr); } - -static void sendfile_cb(uv_fs_t* req) { +static void sendfile_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &sendfile_req); ASSERT_EQ(req->fs_type, UV_FS_SENDFILE); ASSERT_EQ(65545, req->result); @@ -696,8 +665,7 @@ static void sendfile_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } - -static void sendfile_nodata_cb(uv_fs_t* req) { +static void sendfile_nodata_cb(uv_fs_t *req) { ASSERT_PTR_EQ(req, &sendfile_req); ASSERT_EQ(req->fs_type, UV_FS_SENDFILE); ASSERT_OK(req->result); @@ -705,29 +673,27 @@ static void sendfile_nodata_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } - -static void open_noent_cb(uv_fs_t* req) { +static void open_noent_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_OPEN); ASSERT_EQ(req->result, UV_ENOENT); open_cb_count++; uv_fs_req_cleanup(req); } -static void open_nametoolong_cb(uv_fs_t* req) { +static void open_nametoolong_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_OPEN); ASSERT_EQ(req->result, UV_ENAMETOOLONG); open_cb_count++; uv_fs_req_cleanup(req); } -static void open_loop_cb(uv_fs_t* req) { +static void open_loop_cb(uv_fs_t *req) { ASSERT_EQ(req->fs_type, UV_FS_OPEN); ASSERT_EQ(req->result, UV_ELOOP); open_cb_count++; uv_fs_req_cleanup(req); } - TEST_IMPL(fs_file_noent) { uv_fs_t req; int r; @@ -821,11 +787,9 @@ TEST_IMPL(fs_file_loop) { return 0; } -static void check_utime(const char* path, - double atime, - double mtime, +static void check_utime(const char *path, double atime, double mtime, int test_lutime) { - uv_stat_t* s; + uv_stat_t *s; uv_fs_t req; int r; @@ -848,11 +812,11 @@ static void check_utime(const char* path, */ if (s->st_atim.tv_nsec == 0) { if (is_win32) - ASSERT_DOUBLE_EQ(atime, (long) atime); - if (atime > 0 || (long) atime == atime) - ASSERT_EQ(s->st_atim.tv_sec, (long) atime); - ASSERT_GE(s->st_atim.tv_sec, (long) atime - 1); - ASSERT_LE(s->st_atim.tv_sec, (long) atime); + ASSERT_DOUBLE_EQ(atime, (long)atime); + if (atime > 0 || (long)atime == atime) + ASSERT_EQ(s->st_atim.tv_sec, (long)atime); + ASSERT_GE(s->st_atim.tv_sec, (long)atime - 1); + ASSERT_LE(s->st_atim.tv_sec, (long)atime); } else { double st_atim; /* TODO(vtjnash): would it be better to normalize this? */ @@ -869,7 +833,7 @@ static void check_utime(const char* path, /* We test with timestamps that are in the distant past * (if you're a Gen Z-er) so check it's more recent than that. */ - ASSERT_GT(s->st_atim.tv_sec, 1739710000); + ASSERT_GT(s->st_atim.tv_sec, 1739710000); } else { ASSERT_OK(0); } @@ -883,11 +847,11 @@ static void check_utime(const char* path, */ if (s->st_mtim.tv_nsec == 0) { if (is_win32) - ASSERT_DOUBLE_EQ(mtime, (long) atime); - if (mtime > 0 || (long) mtime == mtime) - ASSERT_EQ(s->st_mtim.tv_sec, (long) mtime); - ASSERT_GE(s->st_mtim.tv_sec, (long) mtime - 1); - ASSERT_LE(s->st_mtim.tv_sec, (long) mtime); + ASSERT_DOUBLE_EQ(mtime, (long)atime); + if (mtime > 0 || (long)mtime == mtime) + ASSERT_EQ(s->st_mtim.tv_sec, (long)mtime); + ASSERT_GE(s->st_mtim.tv_sec, (long)mtime - 1); + ASSERT_LE(s->st_mtim.tv_sec, (long)mtime); } else { double st_mtim; /* TODO(vtjnash): would it be better to normalize this? */ @@ -900,7 +864,7 @@ static void check_utime(const char* path, /* We test with timestamps that are in the distant past * (if you're a Gen Z-er) so check it's more recent than that. */ - ASSERT_GT(s->st_mtim.tv_sec, 1739710000); + ASSERT_GT(s->st_mtim.tv_sec, 1739710000); } else { ASSERT_OK(0); } @@ -908,9 +872,8 @@ static void check_utime(const char* path, uv_fs_req_cleanup(&req); } - -static void utime_cb(uv_fs_t* req) { - utime_check_t* c; +static void utime_cb(uv_fs_t *req) { + utime_check_t *c; ASSERT_PTR_EQ(req, &utime_req); ASSERT_OK(req->result); @@ -923,9 +886,8 @@ static void utime_cb(uv_fs_t* req) { utime_cb_count++; } - -static void futime_cb(uv_fs_t* req) { - utime_check_t* c; +static void futime_cb(uv_fs_t *req) { + utime_check_t *c; ASSERT_PTR_EQ(req, &futime_req); ASSERT_OK(req->result); @@ -938,9 +900,8 @@ static void futime_cb(uv_fs_t* req) { futime_cb_count++; } - -static void lutime_cb(uv_fs_t* req) { - utime_check_t* c; +static void lutime_cb(uv_fs_t *req) { + utime_check_t *c; ASSERT_OK(req->result); ASSERT_EQ(req->fs_type, UV_FS_LUTIME); @@ -952,7 +913,6 @@ static void lutime_cb(uv_fs_t* req) { lutime_cb_count++; } - TEST_IMPL(fs_file_async) { int r; @@ -963,7 +923,7 @@ TEST_IMPL(fs_file_async) { loop = uv_default_loop(); r = uv_fs_open(loop, &open_req1, "test_file", UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IRUSR | S_IWUSR, create_cb); + S_IRUSR | S_IWUSR, create_cb); ASSERT_OK(r); uv_run(loop, UV_RUN_DEFAULT); @@ -1015,7 +975,6 @@ TEST_IMPL(fs_file_async) { return 0; } - static void fs_file_sync(int add_flags) { int r; @@ -1072,7 +1031,7 @@ static void fs_file_sync(int add_flags) { uv_fs_req_cleanup(&rename_req); r = uv_fs_open(NULL, &open_req1, "test_file2", UV_FS_O_RDONLY | add_flags, 0, - NULL); + NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -1117,7 +1076,8 @@ TEST_IMPL(fs_posix_delete) { r = uv_fs_mkdir(NULL, &mkdir_req, "test_dir", 0755, NULL); ASSERT_OK(r); - r = uv_fs_open(NULL, &open_req_noclose, "test_dir/file", UV_FS_O_WRONLY | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); + r = uv_fs_open(NULL, &open_req_noclose, "test_dir/file", + UV_FS_O_WRONLY | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); uv_fs_req_cleanup(&open_req_noclose); @@ -1137,7 +1097,8 @@ TEST_IMPL(fs_posix_delete) { ASSERT_OK(unlink_req.result); uv_fs_req_cleanup(&unlink_req); - /* delete the dir while the file is still open, which should succeed on posix */ + /* delete the dir while the file is still open, which should succeed on posix + */ r = uv_fs_rmdir(NULL, &rmdir_req, "test_dir", NULL); ASSERT_OK(r); ASSERT_OK(rmdir_req.result); @@ -1188,7 +1149,6 @@ TEST_IMPL(fs_file_write_null_buffer) { return 0; } - TEST_IMPL(fs_async_dir) { int r; uv_dirent_t dent; @@ -1208,8 +1168,7 @@ TEST_IMPL(fs_async_dir) { /* Create 2 files synchronously. */ r = uv_fs_open(NULL, &open_req1, "test_dir/file1", - UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + UV_FS_O_WRONLY | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); uv_fs_req_cleanup(&open_req1); r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); @@ -1217,8 +1176,7 @@ TEST_IMPL(fs_async_dir) { uv_fs_req_cleanup(&close_req); r = uv_fs_open(NULL, &open_req1, "test_dir/file2", - UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + UV_FS_O_WRONLY | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); uv_fs_req_cleanup(&open_req1); r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); @@ -1285,8 +1243,8 @@ TEST_IMPL(fs_async_dir) { return 0; } - -static int test_sendfile(void (*setup)(int), uv_fs_cb cb, size_t expected_size) { +static int test_sendfile(void (*setup)(int), uv_fs_cb cb, + size_t expected_size) { int f, r; struct stat s1, s2; uv_fs_t req; @@ -1314,13 +1272,13 @@ static int test_sendfile(void (*setup)(int), uv_fs_cb cb, size_t expected_size) uv_fs_req_cleanup(&open_req1); r = uv_fs_open(NULL, &open_req2, "test_file2", UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req2.result, 0); uv_fs_req_cleanup(&open_req2); - r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result, - 1, 131072, cb); + r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result, 1, + 131072, cb); ASSERT_OK(r); uv_run(loop, UV_RUN_DEFAULT); @@ -1365,27 +1323,23 @@ static int test_sendfile(void (*setup)(int), uv_fs_cb cb, size_t expected_size) return 0; } - static void sendfile_setup(int f) { ASSERT_EQ(6, write(f, "begin\n", 6)); ASSERT_EQ(65542, lseek(f, 65536, SEEK_CUR)); ASSERT_EQ(4, write(f, "end\n", 4)); } - TEST_IMPL(fs_async_sendfile) { return test_sendfile(sendfile_setup, sendfile_cb, 65545); } - TEST_IMPL(fs_async_sendfile_nodata) { return test_sendfile(NULL, sendfile_nodata_cb, 0); } - TEST_IMPL(fs_mkdtemp) { int r; - const char* path_template = "test_dir_XXXXXX"; + const char *path_template = "test_dir_XXXXXX"; loop = uv_default_loop(); @@ -1413,7 +1367,6 @@ TEST_IMPL(fs_mkdtemp) { return 0; } - TEST_IMPL(fs_mkstemp) { int r; int fd; @@ -1481,12 +1434,11 @@ TEST_IMPL(fs_mkstemp) { return 0; } - TEST_IMPL(fs_fstat) { int r; uv_fs_t req; uv_file file; - uv_stat_t* s; + uv_stat_t *s; #ifndef _WIN32 struct stat t; #endif @@ -1504,7 +1456,7 @@ TEST_IMPL(fs_fstat) { loop = uv_default_loop(); r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); file = req.result; @@ -1516,10 +1468,10 @@ TEST_IMPL(fs_fstat) { ASSERT_OK(uv_fs_fstat(NULL, &req, file, NULL)); ASSERT_OK(req.result); s = req.ptr; -# if defined(__APPLE__) +#if defined(__APPLE__) ASSERT_EQ(s->st_birthtim.tv_sec, t.st_birthtimespec.tv_sec); ASSERT_EQ(s->st_birthtim.tv_nsec, t.st_birthtimespec.tv_nsec); -# elif defined(__linux__) +#elif defined(__linux__) /* If statx() is supported, the birth time should be equal to the change time * because we just created the file. On older kernels, it's set to zero. */ @@ -1527,7 +1479,7 @@ TEST_IMPL(fs_fstat) { s->st_birthtim.tv_sec == t.st_ctim.tv_sec); ASSERT(s->st_birthtim.tv_nsec == 0 || s->st_birthtim.tv_nsec == t.st_ctim.tv_nsec); -# endif +#endif #endif iov = uv_buf_init(test_buf, sizeof(test_buf)); @@ -1547,16 +1499,16 @@ TEST_IMPL(fs_fstat) { r = fstat(file, &t); ASSERT_OK(r); - ASSERT_EQ(s->st_dev, (uint64_t) t.st_dev); - ASSERT_EQ(s->st_mode, (uint64_t) t.st_mode); - ASSERT_EQ(s->st_nlink, (uint64_t) t.st_nlink); - ASSERT_EQ(s->st_uid, (uint64_t) t.st_uid); - ASSERT_EQ(s->st_gid, (uint64_t) t.st_gid); - ASSERT_EQ(s->st_rdev, (uint64_t) t.st_rdev); - ASSERT_EQ(s->st_ino, (uint64_t) t.st_ino); - ASSERT_EQ(s->st_size, (uint64_t) t.st_size); - ASSERT_EQ(s->st_blksize, (uint64_t) t.st_blksize); - ASSERT_EQ(s->st_blocks, (uint64_t) t.st_blocks); + ASSERT_EQ(s->st_dev, (uint64_t)t.st_dev); + ASSERT_EQ(s->st_mode, (uint64_t)t.st_mode); + ASSERT_EQ(s->st_nlink, (uint64_t)t.st_nlink); + ASSERT_EQ(s->st_uid, (uint64_t)t.st_uid); + ASSERT_EQ(s->st_gid, (uint64_t)t.st_gid); + ASSERT_EQ(s->st_rdev, (uint64_t)t.st_rdev); + ASSERT_EQ(s->st_ino, (uint64_t)t.st_ino); + ASSERT_EQ(s->st_size, (uint64_t)t.st_size); + ASSERT_EQ(s->st_blksize, (uint64_t)t.st_blksize); + ASSERT_EQ(s->st_blocks, (uint64_t)t.st_blocks); #if defined(__APPLE__) ASSERT_EQ(s->st_atim.tv_sec, t.st_atimespec.tv_sec); ASSERT_EQ(s->st_atim.tv_nsec, t.st_atimespec.tv_nsec); @@ -1564,8 +1516,7 @@ TEST_IMPL(fs_fstat) { ASSERT_EQ(s->st_mtim.tv_nsec, t.st_mtimespec.tv_nsec); ASSERT_EQ(s->st_ctim.tv_sec, t.st_ctimespec.tv_sec); ASSERT_EQ(s->st_ctim.tv_nsec, t.st_ctimespec.tv_nsec); -#elif defined(_AIX) || \ - defined(__MVS__) +#elif defined(_AIX) || defined(__MVS__) ASSERT_EQ(s->st_atim.tv_sec, t.st_atime); ASSERT_OK(s->st_atim.tv_nsec); ASSERT_EQ(s->st_mtim.tv_sec, t.st_mtime); @@ -1579,27 +1530,20 @@ TEST_IMPL(fs_fstat) { ASSERT_EQ(s->st_mtim.tv_nsec, t.st_mtimensec); ASSERT_EQ(s->st_ctim.tv_sec, t.st_ctime); ASSERT_EQ(s->st_ctim.tv_nsec, t.st_ctimensec); -#elif defined(__sun) || \ - defined(__DragonFly__) || \ - defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) || \ - defined(_GNU_SOURCE) || \ - defined(_BSD_SOURCE) || \ - defined(_SVID_SOURCE) || \ - defined(_XOPEN_SOURCE) || \ - defined(_DEFAULT_SOURCE) +#elif defined(__sun) || defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__OpenBSD__) || defined(__NetBSD__) || defined(_GNU_SOURCE) || \ + defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) || \ + defined(_DEFAULT_SOURCE) ASSERT_EQ(s->st_atim.tv_sec, t.st_atim.tv_sec); ASSERT_EQ(s->st_atim.tv_nsec, t.st_atim.tv_nsec); ASSERT_EQ(s->st_mtim.tv_sec, t.st_mtim.tv_sec); ASSERT_EQ(s->st_mtim.tv_nsec, t.st_mtim.tv_nsec); ASSERT_EQ(s->st_ctim.tv_sec, t.st_ctim.tv_sec); ASSERT_EQ(s->st_ctim.tv_nsec, t.st_ctim.tv_nsec); -# if defined(__FreeBSD__) || \ - defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) ASSERT_EQ(s->st_birthtim.tv_sec, t.st_birthtim.tv_sec); ASSERT_EQ(s->st_birthtim.tv_nsec, t.st_birthtim.tv_nsec); -# endif +#endif #else ASSERT_EQ(s->st_atim.tv_sec, t.st_atime); ASSERT_OK(s->st_atim.tv_nsec); @@ -1626,7 +1570,6 @@ TEST_IMPL(fs_fstat) { uv_run(loop, UV_RUN_DEFAULT); ASSERT_EQ(1, fstat_cb_count); - r = uv_fs_close(NULL, &req, file, NULL); ASSERT_OK(r); ASSERT_OK(req.result); @@ -1645,20 +1588,19 @@ TEST_IMPL(fs_fstat) { return 0; } - TEST_IMPL(fs_fstat_st_dev) { uv_fs_t req; uv_fs_t req_link; - uv_loop_t* loop = uv_default_loop(); - char* test_file = "tmp_st_dev"; - char* symlink_file = "tmp_st_dev_link"; + uv_loop_t *loop = uv_default_loop(); + char *test_file = "tmp_st_dev"; + char *symlink_file = "tmp_st_dev_link"; unlink(test_file); unlink(symlink_file); // Create file int r = uv_fs_open(NULL, &req, test_file, UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); uv_fs_req_cleanup(&req); @@ -1677,7 +1619,8 @@ TEST_IMPL(fs_fstat_st_dev) { ASSERT_EQ(r, 0); // Compare st_dev - ASSERT_EQ(((uv_stat_t*)req.ptr)->st_dev, ((uv_stat_t*)req_link.ptr)->st_dev); + ASSERT_EQ(((uv_stat_t *)req.ptr)->st_dev, + ((uv_stat_t *)req_link.ptr)->st_dev); // Cleanup uv_fs_req_cleanup(&req); @@ -1689,13 +1632,12 @@ TEST_IMPL(fs_fstat_st_dev) { return 0; } - TEST_IMPL(fs_fstat_stdio) { int fd; int res; uv_fs_t req; #ifdef _WIN32 - uv_stat_t* st; + uv_stat_t *st; DWORD ft; #endif @@ -1714,7 +1656,7 @@ TEST_IMPL(fs_fstat_stdio) { ASSERT_EQ(1, st->st_nlink); ASSERT_EQ(st->st_rdev, (ft == UV_TTY ? FILE_DEVICE_CONSOLE : FILE_DEVICE_NAMED_PIPE) - << 16); + << 16); break; default: break; @@ -1728,7 +1670,6 @@ TEST_IMPL(fs_fstat_stdio) { return 0; } - TEST_IMPL(fs_access) { int r; uv_fs_t req; @@ -1804,7 +1745,6 @@ TEST_IMPL(fs_access) { return 0; } - TEST_IMPL(fs_chmod) { int r; uv_fs_t req; @@ -1816,7 +1756,7 @@ TEST_IMPL(fs_chmod) { loop = uv_default_loop(); r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); file = req.result; @@ -1902,7 +1842,6 @@ TEST_IMPL(fs_chmod) { return 0; } - TEST_IMPL(fs_unlink_readonly) { int r; uv_fs_t req; @@ -1913,10 +1852,8 @@ TEST_IMPL(fs_unlink_readonly) { loop = uv_default_loop(); - r = uv_fs_open(NULL, - &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); file = req.result; @@ -1945,9 +1882,9 @@ TEST_IMPL(fs_unlink_readonly) { uv_fs_req_cleanup(&req); /* - * Run the loop just to check we don't have make any extraneous uv_ref() - * calls. This should drop out immediately. - */ + * Run the loop just to check we don't have make any extraneous uv_ref() + * calls. This should drop out immediately. + */ uv_run(loop, UV_RUN_DEFAULT); /* Cleanup. */ @@ -1970,10 +1907,8 @@ TEST_IMPL(fs_unlink_archive_readonly) { loop = uv_default_loop(); - r = uv_fs_open(NULL, - &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); file = req.result; @@ -2001,9 +1936,9 @@ TEST_IMPL(fs_unlink_archive_readonly) { uv_fs_req_cleanup(&req); /* - * Run the loop just to check we don't have make any extraneous uv_ref() - * calls. This should drop out immediately. - */ + * Run the loop just to check we don't have make any extraneous uv_ref() + * calls. This should drop out immediately. + */ uv_run(loop, UV_RUN_DEFAULT); /* Cleanup. */ @@ -2028,7 +1963,7 @@ TEST_IMPL(fs_chown) { loop = uv_default_loop(); r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); file = req.result; @@ -2108,7 +2043,6 @@ TEST_IMPL(fs_chown) { return 0; } - TEST_IMPL(fs_link) { int r; uv_fs_t req; @@ -2123,7 +2057,7 @@ TEST_IMPL(fs_link) { loop = uv_default_loop(); r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); file = req.result; @@ -2194,7 +2128,6 @@ TEST_IMPL(fs_link) { return 0; } - TEST_IMPL(fs_readlink) { /* Must return UV_ENOENT on an inexistent file */ { @@ -2248,7 +2181,6 @@ TEST_IMPL(fs_readlink) { return 0; } - TEST_IMPL(fs_realpath) { uv_fs_t req; @@ -2269,7 +2201,6 @@ TEST_IMPL(fs_realpath) { return 0; } - TEST_IMPL(fs_symlink) { int r; uv_fs_t req; @@ -2296,7 +2227,7 @@ TEST_IMPL(fs_symlink) { loop = uv_default_loop(); r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); file = req.result; @@ -2348,12 +2279,8 @@ TEST_IMPL(fs_symlink) { uv_fs_close(loop, &req, link, NULL); - r = uv_fs_symlink(NULL, - &req, - "test_file_symlink", - "test_file_symlink_symlink", - 0, - NULL); + r = uv_fs_symlink(NULL, &req, "test_file_symlink", + "test_file_symlink_symlink", 0, NULL); ASSERT_OK(r); uv_fs_req_cleanup(&req); @@ -2376,11 +2303,7 @@ TEST_IMPL(fs_symlink) { uv_fs_req_cleanup(&req); /* async link */ - r = uv_fs_symlink(loop, - &req, - "test_file", - "test_file_symlink2", - 0, + r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink2", 0, symlink_cb); ASSERT_OK(r); uv_run(loop, UV_RUN_DEFAULT); @@ -2401,12 +2324,8 @@ TEST_IMPL(fs_symlink) { uv_fs_close(loop, &req, link, NULL); - r = uv_fs_symlink(NULL, - &req, - "test_file_symlink2", - "test_file_symlink2_symlink", - 0, - NULL); + r = uv_fs_symlink(NULL, &req, "test_file_symlink2", + "test_file_symlink2_symlink", 0, NULL); ASSERT_OK(r); uv_fs_req_cleanup(&req); @@ -2437,11 +2356,10 @@ TEST_IMPL(fs_symlink) { return 0; } - int test_symlink_dir_impl(int type) { uv_fs_t req; int r; - char* test_dir; + char *test_dir; uv_dirent_t dent; static char test_dir_abs_buf[PATHMAX]; size_t test_dir_abs_size; @@ -2485,7 +2403,7 @@ int test_symlink_dir_impl(int type) { r = uv_fs_stat(NULL, &req, "test_dir_symlink", NULL); ASSERT_OK(r); - ASSERT(((uv_stat_t*)req.ptr)->st_mode & S_IFDIR); + ASSERT(((uv_stat_t *)req.ptr)->st_mode & S_IFDIR); uv_fs_req_cleanup(&req); r = uv_fs_lstat(NULL, &req, "test_dir_symlink", NULL); @@ -2493,16 +2411,16 @@ int test_symlink_dir_impl(int type) { #if defined(__MSYS__) RETURN_SKIP("symlink reading is not supported on MSYS2"); #endif - ASSERT(((uv_stat_t*)req.ptr)->st_mode & S_IFLNK); + ASSERT(((uv_stat_t *)req.ptr)->st_mode & S_IFLNK); #ifdef _WIN32 - ASSERT_EQ(((uv_stat_t*)req.ptr)->st_size, strlen(test_dir + 4)); + ASSERT_EQ(((uv_stat_t *)req.ptr)->st_size, strlen(test_dir + 4)); #else -# ifdef __PASE__ +#ifdef __PASE__ /* On IBMi PASE, st_size returns the length of the symlink itself. */ - ASSERT_EQ(((uv_stat_t*)req.ptr)->st_size, strlen("test_dir_symlink")); -# else - ASSERT_EQ(((uv_stat_t*)req.ptr)->st_size, strlen(test_dir)); -# endif + ASSERT_EQ(((uv_stat_t *)req.ptr)->st_size, strlen("test_dir_symlink")); +#else + ASSERT_EQ(((uv_stat_t *)req.ptr)->st_size, strlen(test_dir)); +#endif #endif uv_fs_req_cleanup(&req); @@ -2526,8 +2444,7 @@ int test_symlink_dir_impl(int type) { uv_fs_req_cleanup(&req); r = uv_fs_open(NULL, &open_req1, "test_dir/file1", - UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + UV_FS_O_WRONLY | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); uv_fs_req_cleanup(&open_req1); r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); @@ -2535,8 +2452,7 @@ int test_symlink_dir_impl(int type) { uv_fs_req_cleanup(&close_req); r = uv_fs_open(NULL, &open_req1, "test_dir/file2", - UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + UV_FS_O_WRONLY | UV_FS_O_CREAT, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); uv_fs_req_cleanup(&open_req1); r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); @@ -2584,9 +2500,7 @@ int test_symlink_dir_impl(int type) { return 0; } -TEST_IMPL(fs_symlink_dir) { - return test_symlink_dir_impl(UV_FS_SYMLINK_DIR); -} +TEST_IMPL(fs_symlink_dir) { return test_symlink_dir_impl(UV_FS_SYMLINK_DIR); } TEST_IMPL(fs_symlink_junction) { return test_symlink_dir_impl(UV_FS_SYMLINK_JUNCTION); @@ -2610,14 +2524,10 @@ TEST_IMPL(fs_non_symlink_reparse_point) { uv_fs_mkdir(NULL, &req, "test_dir", 0777, NULL); uv_fs_req_cleanup(&req); - file_handle = CreateFile("test_dir/test_file", - GENERIC_WRITE | FILE_WRITE_ATTRIBUTES, - 0, - NULL, - CREATE_ALWAYS, - FILE_FLAG_OPEN_REPARSE_POINT | - FILE_FLAG_BACKUP_SEMANTICS, - NULL); + file_handle = CreateFile( + "test_dir/test_file", GENERIC_WRITE | FILE_WRITE_ATTRIBUTES, 0, NULL, + CREATE_ALWAYS, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, + NULL); ASSERT_PTR_NE(file_handle, INVALID_HANDLE_VALUE); memset(&reparse_buffer, 0, REPARSE_GUID_DATA_BUFFER_HEADER_SIZE); @@ -2625,14 +2535,9 @@ TEST_IMPL(fs_non_symlink_reparse_point) { reparse_buffer.ReparseDataLength = 0; reparse_buffer.ReparseGuid = REPARSE_GUID; - r = DeviceIoControl(file_handle, - FSCTL_SET_REPARSE_POINT, - &reparse_buffer, - REPARSE_GUID_DATA_BUFFER_HEADER_SIZE, - NULL, - 0, - &bytes_returned, - NULL); + r = DeviceIoControl(file_handle, FSCTL_SET_REPARSE_POINT, &reparse_buffer, + REPARSE_GUID_DATA_BUFFER_HEADER_SIZE, NULL, 0, + &bytes_returned, NULL); ASSERT(r); CloseHandle(file_handle); @@ -2641,34 +2546,34 @@ TEST_IMPL(fs_non_symlink_reparse_point) { ASSERT(r == UV_EINVAL && GetLastError() == ERROR_SYMLINK_NOT_SUPPORTED); uv_fs_req_cleanup(&req); -/* - Placeholder tests for exercising the behavior fixed in issue #995. - To run, update the path with the IP address of a Mac with the hard drive - shared via SMB as "Macintosh HD". + /* + Placeholder tests for exercising the behavior fixed in issue #995. + To run, update the path with the IP address of a Mac with the hard drive + shared via SMB as "Macintosh HD". - r = uv_fs_stat(NULL, &req, "\\\\\\Macintosh HD\\.DS_Store", NULL); - ASSERT_OK(r); - uv_fs_req_cleanup(&req); + r = uv_fs_stat(NULL, &req, "\\\\\\Macintosh HD\\.DS_Store", NULL); + ASSERT_OK(r); + uv_fs_req_cleanup(&req); - r = uv_fs_lstat(NULL, &req, "\\\\\\Macintosh HD\\.DS_Store", NULL); - ASSERT_OK(r); - uv_fs_req_cleanup(&req); -*/ + r = uv_fs_lstat(NULL, &req, "\\\\\\Macintosh HD\\.DS_Store", NULL); + ASSERT_OK(r); + uv_fs_req_cleanup(&req); + */ -/* - uv_fs_stat and uv_fs_lstat can only work on non-symlink reparse - points when a minifilter driver is registered which intercepts - associated filesystem requests. Installing a driver is beyond - the scope of this test. + /* + uv_fs_stat and uv_fs_lstat can only work on non-symlink reparse + points when a minifilter driver is registered which intercepts + associated filesystem requests. Installing a driver is beyond + the scope of this test. - r = uv_fs_stat(NULL, &req, "test_dir/test_file", NULL); - ASSERT_OK(r); - uv_fs_req_cleanup(&req); + r = uv_fs_stat(NULL, &req, "test_dir/test_file", NULL); + ASSERT_OK(r); + uv_fs_req_cleanup(&req); - r = uv_fs_lstat(NULL, &req, "test_dir/test_file", NULL); - ASSERT_OK(r); - uv_fs_req_cleanup(&req); -*/ + r = uv_fs_lstat(NULL, &req, "test_dir/test_file", NULL); + ASSERT_OK(r); + uv_fs_req_cleanup(&req); + */ r = uv_fs_scandir(NULL, &scandir_req, "test_dir", 0, NULL); ASSERT_EQ(1, r); @@ -2694,7 +2599,7 @@ TEST_IMPL(fs_non_symlink_reparse_point) { } TEST_IMPL(fs_lstat_windows_store_apps) { - uv_loop_t* loop; + uv_loop_t *loop; char localappdata[MAX_PATH]; char windowsapps_path[MAX_PATH]; char file_path[MAX_PATH]; @@ -2713,10 +2618,8 @@ TEST_IMPL(fs_lstat_windows_store_apps) { return TEST_SKIP; } ASSERT_OK(r); - r = snprintf(windowsapps_path, - sizeof(localappdata), - "%s\\Microsoft\\WindowsApps", - localappdata); + r = snprintf(windowsapps_path, sizeof(localappdata), + "%s\\Microsoft\\WindowsApps", localappdata); ASSERT_GT(r, 0); if (uv_fs_opendir(loop, &req, windowsapps_path, NULL) != 0) { /* If we cannot read the directory, skip the test. */ @@ -2731,10 +2634,7 @@ TEST_IMPL(fs_lstat_windows_store_apps) { if (dirent.type != UV_DIRENT_LINK) { continue; } - if (snprintf(file_path, - sizeof(file_path), - "%s\\%s", - windowsapps_path, + if (snprintf(file_path, sizeof(file_path), "%s\\%s", windowsapps_path, dirent.name) < 0) { continue; } @@ -2745,10 +2645,9 @@ TEST_IMPL(fs_lstat_windows_store_apps) { } #endif - TEST_IMPL(fs_utime) { utime_check_t checkme; - const char* path = "test_file"; + const char *path = "test_file"; double atime; double mtime; uv_fs_t req; @@ -2758,8 +2657,7 @@ TEST_IMPL(fs_utime) { loop = uv_default_loop(); unlink(path); r = uv_fs_open(NULL, &req, path, UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); uv_fs_req_cleanup(&req); @@ -2772,22 +2670,14 @@ TEST_IMPL(fs_utime) { uv_fs_req_cleanup(&req); check_utime(path, atime, mtime, /* test_lutime */ 0); - ASSERT_OK(uv_fs_utime(NULL, - &req, - path, - UV_FS_UTIME_OMIT, - UV_FS_UTIME_OMIT, - NULL)); + ASSERT_OK( + uv_fs_utime(NULL, &req, path, UV_FS_UTIME_OMIT, UV_FS_UTIME_OMIT, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(path, atime, mtime, /* test_lutime */ 0); - ASSERT_OK(uv_fs_utime(NULL, - &req, - path, - UV_FS_UTIME_NOW, - UV_FS_UTIME_OMIT, - NULL)); + ASSERT_OK( + uv_fs_utime(NULL, &req, path, UV_FS_UTIME_NOW, UV_FS_UTIME_OMIT, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(path, UV_FS_UTIME_NOW, mtime, /* test_lutime */ 0); @@ -2797,12 +2687,8 @@ TEST_IMPL(fs_utime) { uv_fs_req_cleanup(&req); check_utime(path, atime, mtime, /* test_lutime */ 0); - ASSERT_OK(uv_fs_utime(NULL, - &req, - path, - UV_FS_UTIME_OMIT, - UV_FS_UTIME_NOW, - NULL)); + ASSERT_OK( + uv_fs_utime(NULL, &req, path, UV_FS_UTIME_OMIT, UV_FS_UTIME_NOW, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(path, atime, UV_FS_UTIME_NOW, /* test_lutime */ 0); @@ -2826,7 +2712,6 @@ TEST_IMPL(fs_utime) { return 0; } - TEST_IMPL(fs_utime_round) { const char path[] = "test_file"; double atime; @@ -2839,24 +2724,21 @@ TEST_IMPL(fs_utime_round) { loop = uv_default_loop(); unlink(path); r = uv_fs_open(NULL, &req, path, UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); uv_fs_req_cleanup(&req); ASSERT_OK(uv_fs_close(loop, &req, r, NULL)); - atime = mtime = -14245440.25; /* 1969-07-20T02:56:00.25Z */ + atime = mtime = -14245440.25; /* 1969-07-20T02:56:00.25Z */ r = uv_fs_utime(NULL, &req, path, atime, mtime, NULL); -#if !defined(__linux__) && \ - !defined(_WIN32) && \ - !defined(__APPLE__) && \ - !defined(__FreeBSD__) && \ - !defined(__sun) +#if !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__) && \ + !defined(__FreeBSD__) && !defined(__sun) if (r != 0) { ASSERT_EQ(r, UV_EINVAL); - RETURN_SKIP("utime on some OS (z/OS, IBM i PASE, AIX) or filesystems may reject pre-epoch timestamps"); + RETURN_SKIP("utime on some OS (z/OS, IBM i PASE, AIX) or filesystems may " + "reject pre-epoch timestamps"); } #endif ASSERT_OK(r); @@ -2869,7 +2751,6 @@ TEST_IMPL(fs_utime_round) { return 0; } - #ifdef _WIN32 TEST_IMPL(fs_stat_root) { int r; @@ -2901,10 +2782,9 @@ TEST_IMPL(fs_stat_root) { } #endif - TEST_IMPL(fs_futime) { utime_check_t checkme; - const char* path = "test_file"; + const char *path = "test_file"; double atime; double mtime; uv_file file; @@ -2918,8 +2798,7 @@ TEST_IMPL(fs_futime) { loop = uv_default_loop(); unlink(path); r = uv_fs_open(NULL, &req, path, UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); uv_fs_req_cleanup(&req); @@ -2944,22 +2823,14 @@ TEST_IMPL(fs_futime) { uv_fs_req_cleanup(&req); check_utime(path, atime, mtime, /* test_lutime */ 0); - ASSERT_OK(uv_fs_futime(NULL, - &req, - file, - UV_FS_UTIME_OMIT, - UV_FS_UTIME_OMIT, - NULL)); + ASSERT_OK( + uv_fs_futime(NULL, &req, file, UV_FS_UTIME_OMIT, UV_FS_UTIME_OMIT, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(path, atime, mtime, /* test_lutime */ 0); - ASSERT_OK(uv_fs_futime(NULL, - &req, - file, - UV_FS_UTIME_NOW, - UV_FS_UTIME_OMIT, - NULL)); + ASSERT_OK( + uv_fs_futime(NULL, &req, file, UV_FS_UTIME_NOW, UV_FS_UTIME_OMIT, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(path, UV_FS_UTIME_NOW, mtime, /* test_lutime */ 0); @@ -2969,16 +2840,22 @@ TEST_IMPL(fs_futime) { uv_fs_req_cleanup(&req); check_utime(path, atime, mtime, /* test_lutime */ 0); - ASSERT_OK(uv_fs_futime(NULL, - &req, - file, - UV_FS_UTIME_OMIT, - UV_FS_UTIME_NOW, - NULL)); + ASSERT_OK( + uv_fs_futime(NULL, &req, file, UV_FS_UTIME_OMIT, UV_FS_UTIME_NOW, NULL)); + ASSERT_OK(req.result); + uv_fs_req_cleanup(&req); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(path, atime, UV_FS_UTIME_NOW, /* test_lutime */ 0); + /* Test nanosecond precision */ + atime = mtime = 1.000000123; + r = uv_fs_futime(NULL, &req, file, atime, mtime, NULL); + ASSERT_OK(r); + ASSERT_OK(req.result); + uv_fs_req_cleanup(&req); + check_utime(path, atime, mtime, /* test_lutime */ 0); + atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */ checkme.atime = atime; @@ -2999,23 +2876,20 @@ TEST_IMPL(fs_futime) { return 0; } - TEST_IMPL(fs_lutime) { utime_check_t checkme; - const char* path = "test_file"; - const char* symlink_path = "test_file_symlink"; + const char *path = "test_file"; + const char *symlink_path = "test_file_symlink"; double atime; double mtime; uv_fs_t req; int r, s; - /* Setup */ loop = uv_default_loop(); unlink(path); r = uv_fs_open(NULL, &req, path, UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(req.result, 0); uv_fs_req_cleanup(&req); @@ -3050,22 +2924,14 @@ TEST_IMPL(fs_lutime) { uv_fs_req_cleanup(&req); check_utime(symlink_path, atime, mtime, /* test_lutime */ 1); - ASSERT_OK(uv_fs_lutime(NULL, - &req, - symlink_path, - UV_FS_UTIME_OMIT, - UV_FS_UTIME_OMIT, - NULL)); + ASSERT_OK(uv_fs_lutime(NULL, &req, symlink_path, UV_FS_UTIME_OMIT, + UV_FS_UTIME_OMIT, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(symlink_path, atime, mtime, /* test_lutime */ 1); - ASSERT_OK(uv_fs_lutime(NULL, - &req, - symlink_path, - UV_FS_UTIME_NOW, - UV_FS_UTIME_OMIT, - NULL)); + ASSERT_OK(uv_fs_lutime(NULL, &req, symlink_path, UV_FS_UTIME_NOW, + UV_FS_UTIME_OMIT, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(symlink_path, UV_FS_UTIME_NOW, mtime, /* test_lutime */ 1); @@ -3075,12 +2941,8 @@ TEST_IMPL(fs_lutime) { uv_fs_req_cleanup(&req); check_utime(symlink_path, atime, mtime, /* test_lutime */ 1); - ASSERT_OK(uv_fs_lutime(NULL, - &req, - symlink_path, - UV_FS_UTIME_OMIT, - UV_FS_UTIME_NOW, - NULL)); + ASSERT_OK(uv_fs_lutime(NULL, &req, symlink_path, UV_FS_UTIME_OMIT, + UV_FS_UTIME_NOW, NULL)); ASSERT_OK(req.result); uv_fs_req_cleanup(&req); check_utime(symlink_path, atime, UV_FS_UTIME_NOW, /* test_lutime */ 1); @@ -3106,7 +2968,6 @@ TEST_IMPL(fs_lutime) { return 0; } - TEST_IMPL(fs_stat_missing_path) { uv_fs_t req; int r; @@ -3122,9 +2983,8 @@ TEST_IMPL(fs_stat_missing_path) { return 0; } - TEST_IMPL(fs_scandir_empty_dir) { - const char* path; + const char *path; uv_fs_t req; uv_dirent_t dent; int r; @@ -3159,9 +3019,8 @@ TEST_IMPL(fs_scandir_empty_dir) { return 0; } - TEST_IMPL(fs_scandir_non_existent_dir) { - const char* path; + const char *path; uv_fs_t req; uv_dirent_t dent; int r; @@ -3194,7 +3053,7 @@ TEST_IMPL(fs_scandir_non_existent_dir) { } TEST_IMPL(fs_scandir_file) { - const char* path; + const char *path; int r; path = "test/fixtures/empty_file"; @@ -3215,7 +3074,6 @@ TEST_IMPL(fs_scandir_file) { return 0; } - /* Run in Valgrind. Should not leak when the iterator isn't exhausted. */ TEST_IMPL(fs_scandir_early_exit) { uv_dirent_t d; @@ -3233,9 +3091,8 @@ TEST_IMPL(fs_scandir_early_exit) { return 0; } - TEST_IMPL(fs_open_dir) { - const char* path; + const char *path; uv_fs_t req; int r, file; @@ -3263,7 +3120,6 @@ TEST_IMPL(fs_open_dir) { return 0; } - static void fs_file_open_append(int add_flags) { int r; @@ -3308,7 +3164,7 @@ static void fs_file_open_append(int add_flags) { uv_fs_req_cleanup(&close_req); r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDONLY | add_flags, - S_IRUSR, NULL); + S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -3318,8 +3174,7 @@ static void fs_file_open_append(int add_flags) { printf("read = %d\n", r); ASSERT_EQ(26, r); ASSERT_EQ(26, read_req.result); - ASSERT_OK(memcmp(buf, - "test-buffer\n\0test-buffer\n\0", + ASSERT_OK(memcmp(buf, "test-buffer\n\0test-buffer\n\0", sizeof("test-buffer\n\0test-buffer\n\0") - 1)); uv_fs_req_cleanup(&read_req); @@ -3339,7 +3194,6 @@ TEST_IMPL(fs_file_open_append) { return 0; } - TEST_IMPL(fs_rename_to_existing_file) { int r; @@ -3350,7 +3204,7 @@ TEST_IMPL(fs_rename_to_existing_file) { loop = uv_default_loop(); r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -3367,7 +3221,7 @@ TEST_IMPL(fs_rename_to_existing_file) { uv_fs_req_cleanup(&close_req); r = uv_fs_open(NULL, &open_req1, "test_file2", UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -3408,45 +3262,37 @@ TEST_IMPL(fs_rename_to_existing_file) { return 0; } - static void fs_read_bufs(int add_flags) { char scratch[768]; uv_buf_t bufs[4]; - ASSERT_LE(0, uv_fs_open(NULL, &open_req1, - "test/fixtures/lorem_ipsum.txt", + ASSERT_LE(0, uv_fs_open(NULL, &open_req1, "test/fixtures/lorem_ipsum.txt", UV_FS_O_RDONLY | add_flags, 0, NULL)); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); - ASSERT_EQ(UV_EINVAL, uv_fs_read(NULL, &read_req, open_req1.result, - NULL, 0, 0, NULL)); - ASSERT_EQ(UV_EINVAL, uv_fs_read(NULL, &read_req, open_req1.result, - NULL, 1, 0, NULL)); - ASSERT_EQ(UV_EINVAL, uv_fs_read(NULL, &read_req, open_req1.result, - bufs, 0, 0, NULL)); + ASSERT_EQ(UV_EINVAL, + uv_fs_read(NULL, &read_req, open_req1.result, NULL, 0, 0, NULL)); + ASSERT_EQ(UV_EINVAL, + uv_fs_read(NULL, &read_req, open_req1.result, NULL, 1, 0, NULL)); + ASSERT_EQ(UV_EINVAL, + uv_fs_read(NULL, &read_req, open_req1.result, bufs, 0, 0, NULL)); bufs[0] = uv_buf_init(scratch + 0, 256); bufs[1] = uv_buf_init(scratch + 256, 256); bufs[2] = uv_buf_init(scratch + 512, 128); bufs[3] = uv_buf_init(scratch + 640, 128); - ASSERT_EQ(446, uv_fs_read(NULL, - &read_req, - open_req1.result, - bufs + 0, - 2, /* 2x 256 bytes. */ - 0, /* Positional read. */ + ASSERT_EQ(446, uv_fs_read(NULL, &read_req, open_req1.result, bufs + 0, + 2, /* 2x 256 bytes. */ + 0, /* Positional read. */ NULL)); ASSERT_EQ(446, read_req.result); uv_fs_req_cleanup(&read_req); - ASSERT_EQ(190, uv_fs_read(NULL, - &read_req, - open_req1.result, - bufs + 2, - 2, /* 2x 128 bytes. */ - 256, /* Positional read. */ + ASSERT_EQ(190, uv_fs_read(NULL, &read_req, open_req1.result, bufs + 2, + 2, /* 2x 128 bytes. */ + 256, /* Positional read. */ NULL)); ASSERT_EQ(read_req.result, /* 446 - 256 */ 190); uv_fs_req_cleanup(&read_req); @@ -3466,7 +3312,6 @@ TEST_IMPL(fs_read_bufs) { return 0; } - static void fs_read_file_eof(int add_flags) { #if defined(__CYGWIN__) || defined(__MSYS__) RETURN_SKIP("Cygwin pread at EOF may (incorrectly) return data!"); @@ -3497,7 +3342,7 @@ static void fs_read_file_eof(int add_flags) { uv_fs_req_cleanup(&close_req); r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDONLY | add_flags, 0, - NULL); + NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -3511,8 +3356,8 @@ static void fs_read_file_eof(int add_flags) { uv_fs_req_cleanup(&read_req); iov = uv_buf_init(buf, sizeof(buf)); - r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, - read_req.result, NULL); + r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, read_req.result, + NULL); ASSERT_OK(r); ASSERT_OK(read_req.result); uv_fs_req_cleanup(&read_req); @@ -3533,7 +3378,6 @@ TEST_IMPL(fs_read_file_eof) { return 0; } - static void fs_write_multiple_bufs(int add_flags) { uv_buf_t iovs[2]; int r; @@ -3563,7 +3407,7 @@ static void fs_write_multiple_bufs(int add_flags) { uv_fs_req_cleanup(&close_req); r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDONLY | add_flags, 0, - NULL); + NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -3595,7 +3439,8 @@ static void fs_write_multiple_bufs(int add_flags) { if (read_req.result == sizeof(test_buf)) { /* Infer that preadv is not available. */ uv_fs_req_cleanup(&read_req); - r = uv_fs_read(NULL, &read_req, open_req1.result, &iovs[1], 1, read_req.result, NULL); + r = uv_fs_read(NULL, &read_req, open_req1.result, &iovs[1], 1, + read_req.result, NULL); ASSERT_GE(r, 0); ASSERT_EQ(read_req.result, sizeof(test_buf2)); } else { @@ -3628,12 +3473,11 @@ TEST_IMPL(fs_write_multiple_bufs) { return 0; } - static void fs_write_alotof_bufs(int add_flags) { size_t iovcount; size_t iovmax; - uv_buf_t* iovs; - char* buffer; + uv_buf_t *iovs; + char *buffer; size_t index; int r; @@ -3648,11 +3492,8 @@ static void fs_write_alotof_bufs(int add_flags) { ASSERT_NOT_NULL(iovs); iovmax = uv_test_getiovmax(); - r = uv_fs_open(NULL, - &open_req1, - "test_file", - UV_FS_O_RDWR | UV_FS_O_CREAT | add_flags, - S_IWUSR | S_IRUSR, + r = uv_fs_open(NULL, &open_req1, "test_file", + UV_FS_O_RDWR | UV_FS_O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); @@ -3661,13 +3502,7 @@ static void fs_write_alotof_bufs(int add_flags) { for (index = 0; index < iovcount; ++index) iovs[index] = uv_buf_init(test_buf, sizeof(test_buf)); - r = uv_fs_write(NULL, - &write_req, - open_req1.result, - iovs, - iovcount, - -1, - NULL); + r = uv_fs_write(NULL, &write_req, open_req1.result, iovs, iovcount, -1, NULL); ASSERT_GE(r, 0); ASSERT_EQ((size_t)write_req.result, sizeof(test_buf) * iovcount); uv_fs_req_cleanup(&write_req); @@ -3677,8 +3512,8 @@ static void fs_write_alotof_bufs(int add_flags) { ASSERT_NOT_NULL(buffer); for (index = 0; index < iovcount; ++index) - iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf), - sizeof(test_buf)); + iovs[index] = + uv_buf_init(buffer + index * sizeof(test_buf), sizeof(test_buf)); r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); ASSERT_OK(r); @@ -3686,7 +3521,7 @@ static void fs_write_alotof_bufs(int add_flags) { uv_fs_req_cleanup(&close_req); r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDONLY | add_flags, 0, - NULL); + NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -3698,9 +3533,8 @@ static void fs_write_alotof_bufs(int add_flags) { ASSERT_EQ((size_t)read_req.result, sizeof(test_buf) * iovcount); for (index = 0; index < iovcount; ++index) - ASSERT_OK(strncmp(buffer + index * sizeof(test_buf), - test_buf, - sizeof(test_buf))); + ASSERT_OK( + strncmp(buffer + index * sizeof(test_buf), test_buf, sizeof(test_buf))); uv_fs_req_cleanup(&read_req); free(buffer); @@ -3708,13 +3542,7 @@ static void fs_write_alotof_bufs(int add_flags) { ASSERT_EQ(lseek(open_req1.result, write_req.result, SEEK_SET), write_req.result); iov = uv_buf_init(buf, sizeof(buf)); - r = uv_fs_read(NULL, - &read_req, - open_req1.result, - &iov, - 1, - -1, - NULL); + r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL); ASSERT_OK(r); ASSERT_OK(read_req.result); uv_fs_req_cleanup(&read_req); @@ -3736,16 +3564,15 @@ TEST_IMPL(fs_write_alotof_bufs) { return 0; } - static void fs_write_alotof_bufs_with_offset(int add_flags) { size_t iovcount; size_t iovmax; - uv_buf_t* iovs; - char* buffer; + uv_buf_t *iovs; + char *buffer; size_t index; int r; int64_t offset; - char* filler; + char *filler; int filler_len; filler = "0123456789"; @@ -3761,11 +3588,8 @@ static void fs_write_alotof_bufs_with_offset(int add_flags) { ASSERT_NOT_NULL(iovs); iovmax = uv_test_getiovmax(); - r = uv_fs_open(NULL, - &open_req1, - "test_file", - UV_FS_O_RDWR | UV_FS_O_CREAT | add_flags, - S_IWUSR | S_IRUSR, + r = uv_fs_open(NULL, &open_req1, "test_file", + UV_FS_O_RDWR | UV_FS_O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); @@ -3781,12 +3605,7 @@ static void fs_write_alotof_bufs_with_offset(int add_flags) { for (index = 0; index < iovcount; ++index) iovs[index] = uv_buf_init(test_buf, sizeof(test_buf)); - r = uv_fs_write(NULL, - &write_req, - open_req1.result, - iovs, - iovcount, - offset, + r = uv_fs_write(NULL, &write_req, open_req1.result, iovs, iovcount, offset, NULL); ASSERT_GE(r, 0); ASSERT_EQ((size_t)write_req.result, sizeof(test_buf) * iovcount); @@ -3797,11 +3616,11 @@ static void fs_write_alotof_bufs_with_offset(int add_flags) { ASSERT_NOT_NULL(buffer); for (index = 0; index < iovcount; ++index) - iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf), - sizeof(test_buf)); + iovs[index] = + uv_buf_init(buffer + index * sizeof(test_buf), sizeof(test_buf)); - r = uv_fs_read(NULL, &read_req, open_req1.result, - iovs, iovcount, offset, NULL); + r = uv_fs_read(NULL, &read_req, open_req1.result, iovs, iovcount, offset, + NULL); ASSERT_GE(r, 0); if (r == sizeof(test_buf)) iovcount = 1; /* Infer that preadv is not available. */ @@ -3810,27 +3629,21 @@ static void fs_write_alotof_bufs_with_offset(int add_flags) { ASSERT_EQ((size_t)read_req.result, sizeof(test_buf) * iovcount); for (index = 0; index < iovcount; ++index) - ASSERT_OK(strncmp(buffer + index * sizeof(test_buf), - test_buf, - sizeof(test_buf))); + ASSERT_OK( + strncmp(buffer + index * sizeof(test_buf), test_buf, sizeof(test_buf))); uv_fs_req_cleanup(&read_req); free(buffer); r = uv_fs_stat(NULL, &stat_req, "test_file", NULL); ASSERT_OK(r); - ASSERT_EQ((int64_t)((uv_stat_t*)stat_req.ptr)->st_size, + ASSERT_EQ((int64_t)((uv_stat_t *)stat_req.ptr)->st_size, offset + (int64_t)write_req.result); uv_fs_req_cleanup(&stat_req); iov = uv_buf_init(buf, sizeof(buf)); - r = uv_fs_read(NULL, - &read_req, - open_req1.result, - &iov, - 1, - offset + write_req.result, - NULL); + r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, + offset + write_req.result, NULL); ASSERT_OK(r); ASSERT_OK(read_req.result); uv_fs_req_cleanup(&read_req); @@ -3866,24 +3679,16 @@ TEST_IMPL(fs_read_dir) { /* Setup Done Here */ /* Get a file descriptor for the directory */ - r = uv_fs_open(loop, - &open_req1, - "test_dir", - UV_FS_O_RDONLY | UV_FS_O_DIRECTORY, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(loop, &open_req1, "test_dir", + UV_FS_O_RDONLY | UV_FS_O_DIRECTORY, S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); uv_fs_req_cleanup(&open_req1); /* Try to read data from the directory */ iov = uv_buf_init(buf, sizeof(buf)); r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, 0, NULL); -#if defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) || \ - defined(__DragonFly__) || \ - defined(_AIX) || \ - defined(__sun) || \ +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || \ + defined(__DragonFly__) || defined(_AIX) || defined(__sun) || \ defined(__MVS__) /* * As of now, these operating systems support reading from a directory, @@ -3915,31 +3720,27 @@ TEST_IMPL(fs_read_dir) { #ifdef _WIN32 -TEST_IMPL(fs_partial_read) { - RETURN_SKIP("Test not implemented on Windows."); -} +TEST_IMPL(fs_partial_read) { RETURN_SKIP("Test not implemented on Windows."); } -TEST_IMPL(fs_partial_write) { - RETURN_SKIP("Test not implemented on Windows."); -} +TEST_IMPL(fs_partial_write) { RETURN_SKIP("Test not implemented on Windows."); } -#else /* !_WIN32 */ +#else /* !_WIN32 */ struct thread_ctx { pthread_t pid; int fd; - char* data; + char *data; int size; int interval; int doread; }; -static void thread_main(void* arg) { - const struct thread_ctx* ctx; +static void thread_main(void *arg) { + const struct thread_ctx *ctx; int size; - char* data; + char *data; - ctx = (struct thread_ctx*)arg; + ctx = (struct thread_ctx *)arg; size = ctx->size; data = ctx->data; @@ -3965,11 +3766,11 @@ static void thread_main(void* arg) { } } -static void sig_func(uv_signal_t* handle, int signum) { +static void sig_func(uv_signal_t *handle, int signum) { uv_signal_stop(handle); } -static size_t uv_test_fs_buf_offset(uv_buf_t* bufs, size_t size) { +static size_t uv_test_fs_buf_offset(uv_buf_t *bufs, size_t size) { size_t offset; /* Figure out which bufs are done */ for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset) @@ -3989,8 +3790,8 @@ static void test_fs_partial(int doread) { uv_signal_t signal; int pipe_fds[2]; size_t iovcount; - uv_buf_t* iovs; - char* buffer; + uv_buf_t *iovs; + char *buffer; size_t index; iovcount = 54321; @@ -4008,7 +3809,8 @@ static void test_fs_partial(int doread) { ASSERT_NOT_NULL(buffer); for (index = 0; index < iovcount; ++index) - iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf), sizeof(test_buf)); + iovs[index] = + uv_buf_init(buffer + index * sizeof(test_buf), sizeof(test_buf)); loop = uv_default_loop(); @@ -4021,13 +3823,14 @@ static void test_fs_partial(int doread) { ASSERT_OK(uv_thread_create(&thread, thread_main, &ctx)); if (doread) { - uv_buf_t* read_iovs; + uv_buf_t *read_iovs; int nread; read_iovs = iovs; nread = 0; while (nread < ctx.size) { int result; - result = uv_fs_read(loop, &read_req, pipe_fds[0], read_iovs, iovcount, -1, NULL); + result = uv_fs_read(loop, &read_req, pipe_fds[0], read_iovs, iovcount, -1, + NULL); if (result > 0) { size_t read_iovcount; read_iovcount = uv_test_fs_buf_offset(read_iovs, result); @@ -4041,7 +3844,8 @@ static void test_fs_partial(int doread) { } } else { int result; - result = uv_fs_write(loop, &write_req, pipe_fds[1], iovs, iovcount, -1, NULL); + result = + uv_fs_write(loop, &write_req, pipe_fds[1], iovs, iovcount, -1, NULL); ASSERT_EQ(write_req.result, result); ASSERT_EQ(result, ctx.size); uv_fs_req_cleanup(&write_req); @@ -4054,13 +3858,13 @@ static void test_fs_partial(int doread) { ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT)); ASSERT_OK(close(pipe_fds[1])); - uv_close((uv_handle_t*) &signal, NULL); + uv_close((uv_handle_t *)&signal, NULL); { /* Make sure we read everything that we wrote. */ - int result; - result = uv_fs_read(loop, &read_req, pipe_fds[0], iovs, 1, -1, NULL); - ASSERT_OK(result); - uv_fs_req_cleanup(&read_req); + int result; + result = uv_fs_read(loop, &read_req, pipe_fds[0], iovs, 1, -1, NULL); + ASSERT_OK(result); + uv_fs_req_cleanup(&read_req); } ASSERT_OK(close(pipe_fds[0])); @@ -4081,7 +3885,7 @@ TEST_IMPL(fs_partial_write) { return 0; } -#endif/* _WIN32 */ +#endif /* _WIN32 */ TEST_IMPL(fs_read_write_null_arguments) { int r; @@ -4145,7 +3949,6 @@ TEST_IMPL(fs_read_write_null_arguments) { return 0; } - TEST_IMPL(get_osfhandle_valid_handle) { int r; uv_os_fd_t fd; @@ -4155,10 +3958,8 @@ TEST_IMPL(get_osfhandle_valid_handle) { loop = uv_default_loop(); - r = uv_fs_open(NULL, - &open_req1, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -4192,12 +3993,8 @@ TEST_IMPL(open_osfhandle_valid_handle) { loop = uv_default_loop(); - r = uv_fs_open(NULL, - &open_req1, - "test_file", - UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -4235,10 +4032,8 @@ TEST_IMPL(fs_file_pos_after_op_with_offset) { unlink("test_file"); loop = uv_default_loop(); - r = uv_fs_open(loop, - &open_req1, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(loop, &open_req1, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT, + S_IWUSR | S_IRUSR, NULL); ASSERT_GT(r, 0); uv_fs_req_cleanup(&open_req1); @@ -4333,12 +4128,9 @@ static void fs_file_pos_write(int add_flags) { /* Setup. */ unlink("test_file"); - r = uv_fs_open(NULL, - &open_req1, - "test_file", + r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_RDWR | add_flags, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GT(r, 0); uv_fs_req_cleanup(&open_req1); @@ -4371,12 +4163,9 @@ static void fs_file_pos_append(int add_flags) { /* Setup. */ unlink("test_file"); - r = uv_fs_open(NULL, - &open_req1, - "test_file", + r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_RDWR | add_flags, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GT(r, 0); uv_fs_req_cleanup(&open_req1); @@ -4518,21 +4307,15 @@ TEST_IMPL(fs_exclusive_sharing_mode) { ASSERT_GT(UV_FS_O_EXLOCK, 0); - r = uv_fs_open(NULL, - &open_req1, - "test_file", + r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT | UV_FS_O_EXLOCK, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); - r = uv_fs_open(NULL, - &open_req2, - "test_file", UV_FS_O_RDONLY | UV_FS_O_EXLOCK, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(NULL, &open_req2, "test_file", UV_FS_O_RDONLY | UV_FS_O_EXLOCK, + S_IWUSR | S_IRUSR, NULL); ASSERT_LT(r, 0); ASSERT_LT(open_req2.result, 0); uv_fs_req_cleanup(&open_req2); @@ -4542,11 +4325,8 @@ TEST_IMPL(fs_exclusive_sharing_mode) { ASSERT_OK(close_req.result); uv_fs_req_cleanup(&close_req); - r = uv_fs_open(NULL, - &open_req2, - "test_file", UV_FS_O_RDONLY | UV_FS_O_EXLOCK, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(NULL, &open_req2, "test_file", UV_FS_O_RDONLY | UV_FS_O_EXLOCK, + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req2.result, 0); uv_fs_req_cleanup(&open_req2); @@ -4577,12 +4357,9 @@ TEST_IMPL(fs_file_flag_no_buffering) { ASSERT_GT(UV_FS_O_RDWR, 0); /* FILE_APPEND_DATA must be excluded from FILE_GENERIC_WRITE: */ - r = uv_fs_open(NULL, - &open_req1, - "test_file", + r = uv_fs_open(NULL, &open_req1, "test_file", UV_FS_O_RDWR | UV_FS_O_CREAT | UV_FS_O_DIRECT, - S_IWUSR | S_IRUSR, - NULL); + S_IWUSR | S_IRUSR, NULL); ASSERT_GE(r, 0); ASSERT_GE(open_req1.result, 0); uv_fs_req_cleanup(&open_req1); @@ -4593,12 +4370,8 @@ TEST_IMPL(fs_file_flag_no_buffering) { uv_fs_req_cleanup(&close_req); /* FILE_APPEND_DATA and FILE_FLAG_NO_BUFFERING are mutually exclusive: */ - r = uv_fs_open(NULL, - &open_req2, - "test_file", - UV_FS_O_APPEND | UV_FS_O_DIRECT, - S_IWUSR | S_IRUSR, - NULL); + r = uv_fs_open(NULL, &open_req2, "test_file", UV_FS_O_APPEND | UV_FS_O_DIRECT, + S_IWUSR | S_IRUSR, NULL); ASSERT_EQ(r, UV_EINVAL); ASSERT_EQ(open_req2.result, UV_EINVAL); uv_fs_req_cleanup(&open_req2); @@ -4612,194 +4385,183 @@ TEST_IMPL(fs_file_flag_no_buffering) { #endif #ifdef _WIN32 -int call_icacls(const char* command, ...) { - char icacls_command[1024]; - va_list args; +int call_icacls(const char *command, ...) { + char icacls_command[1024]; + va_list args; - va_start(args, command); - vsnprintf(icacls_command, ARRAYSIZE(icacls_command), command, args); - va_end(args); - return system(icacls_command); + va_start(args, command); + vsnprintf(icacls_command, ARRAYSIZE(icacls_command), command, args); + va_end(args); + return system(icacls_command); } TEST_IMPL(fs_open_readonly_acl) { - uv_passwd_t pwd; - uv_fs_t req; - int r; + uv_passwd_t pwd; + uv_fs_t req; + int r; - /* - Based on Node.js test from - https://github.com/nodejs/node/commit/3ba81e34e86a5c32658e218cb6e65b13e8326bc5 + /* + Based on Node.js test from + https://github.com/nodejs/node/commit/3ba81e34e86a5c32658e218cb6e65b13e8326bc5 - If anything goes wrong, you can delte the test_fle_icacls with: + If anything goes wrong, you can delte the test_fle_icacls with: - icacls test_file_icacls /remove "%USERNAME%" /inheritance:e - attrib -r test_file_icacls - del test_file_icacls - */ + icacls test_file_icacls /remove "%USERNAME%" /inheritance:e + attrib -r test_file_icacls + del test_file_icacls + */ - /* Setup - clear the ACL and remove the file */ - loop = uv_default_loop(); - r = uv_os_get_passwd(&pwd); - ASSERT_OK(r); - call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e", - pwd.username); - uv_fs_chmod(loop, &req, "test_file_icacls", S_IWUSR, NULL); - unlink("test_file_icacls"); + /* Setup - clear the ACL and remove the file */ + loop = uv_default_loop(); + r = uv_os_get_passwd(&pwd); + ASSERT_OK(r); + call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e", + pwd.username); + uv_fs_chmod(loop, &req, "test_file_icacls", S_IWUSR, NULL); + unlink("test_file_icacls"); - /* Create the file */ - r = uv_fs_open(loop, - &open_req1, - "test_file_icacls", - UV_FS_O_RDONLY | UV_FS_O_CREAT, - S_IRUSR, - NULL); - ASSERT_GE(r, 0); - ASSERT_GE(open_req1.result, 0); - uv_fs_req_cleanup(&open_req1); - r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); - ASSERT_OK(r); - ASSERT_OK(close_req.result); - uv_fs_req_cleanup(&close_req); + /* Create the file */ + r = uv_fs_open(loop, &open_req1, "test_file_icacls", + UV_FS_O_RDONLY | UV_FS_O_CREAT, S_IRUSR, NULL); + ASSERT_GE(r, 0); + ASSERT_GE(open_req1.result, 0); + uv_fs_req_cleanup(&open_req1); + r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); + ASSERT_OK(r); + ASSERT_OK(close_req.result); + uv_fs_req_cleanup(&close_req); - /* Set up ACL */ - r = call_icacls("icacls test_file_icacls /inheritance:r /remove \"%s\"", - pwd.username); - if (r != 0) { - goto acl_cleanup; - } - r = call_icacls("icacls test_file_icacls /grant \"%s\":RX", pwd.username); - if (r != 0) { - goto acl_cleanup; - } + /* Set up ACL */ + r = call_icacls("icacls test_file_icacls /inheritance:r /remove \"%s\"", + pwd.username); + if (r != 0) { + goto acl_cleanup; + } + r = call_icacls("icacls test_file_icacls /grant \"%s\":RX", pwd.username); + if (r != 0) { + goto acl_cleanup; + } - /* Try opening the file */ - r = uv_fs_open(NULL, &open_req1, "test_file_icacls", UV_FS_O_RDONLY, 0, - NULL); - if (r < 0) { - goto acl_cleanup; - } - uv_fs_req_cleanup(&open_req1); - r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); - if (r != 0) { - goto acl_cleanup; - } - uv_fs_req_cleanup(&close_req); + /* Try opening the file */ + r = uv_fs_open(NULL, &open_req1, "test_file_icacls", UV_FS_O_RDONLY, 0, NULL); + if (r < 0) { + goto acl_cleanup; + } + uv_fs_req_cleanup(&open_req1); + r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); + if (r != 0) { + goto acl_cleanup; + } + uv_fs_req_cleanup(&close_req); - acl_cleanup: - /* Cleanup */ - call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e", - pwd.username); - unlink("test_file_icacls"); - uv_os_free_passwd(&pwd); - ASSERT_OK(r); - MAKE_VALGRIND_HAPPY(loop); - return 0; +acl_cleanup: + /* Cleanup */ + call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e", + pwd.username); + unlink("test_file_icacls"); + uv_os_free_passwd(&pwd); + ASSERT_OK(r); + MAKE_VALGRIND_HAPPY(loop); + return 0; } TEST_IMPL(fs_stat_no_permission) { - uv_passwd_t pwd; - uv_fs_t req; - int r; - char* filename = "test_file_no_permission.txt"; + uv_passwd_t pwd; + uv_fs_t req; + int r; + char *filename = "test_file_no_permission.txt"; - /* Setup - clear the ACL and remove the file */ - loop = uv_default_loop(); - r = uv_os_get_passwd(&pwd); - ASSERT_OK(r); - call_icacls("icacls %s /remove *S-1-1-0:(F)", filename); - unlink(filename); + /* Setup - clear the ACL and remove the file */ + loop = uv_default_loop(); + r = uv_os_get_passwd(&pwd); + ASSERT_OK(r); + call_icacls("icacls %s /remove *S-1-1-0:(F)", filename); + unlink(filename); - /* Create the file */ - r = uv_fs_open(loop, - &open_req1, - filename, - UV_FS_O_RDONLY | UV_FS_O_CREAT, - S_IRUSR, - NULL); - ASSERT_GE(r, 0); - ASSERT_GE(open_req1.result, 0); - uv_fs_req_cleanup(&open_req1); - r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); - ASSERT_OK(r); - ASSERT_OK(close_req.result); - uv_fs_req_cleanup(&close_req); + /* Create the file */ + r = uv_fs_open(loop, &open_req1, filename, UV_FS_O_RDONLY | UV_FS_O_CREAT, + S_IRUSR, NULL); + ASSERT_GE(r, 0); + ASSERT_GE(open_req1.result, 0); + uv_fs_req_cleanup(&open_req1); + r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); + ASSERT_OK(r); + ASSERT_OK(close_req.result); + uv_fs_req_cleanup(&close_req); - /* Set up ACL */ - r = call_icacls("icacls %s /deny *S-1-1-0:(F)", filename); - if (r != 0) { - goto acl_cleanup; - } + /* Set up ACL */ + r = call_icacls("icacls %s /deny *S-1-1-0:(F)", filename); + if (r != 0) { + goto acl_cleanup; + } - /* Read file stats */ - r = uv_fs_stat(NULL, &req, filename, NULL); - if (r != 0) { - goto acl_cleanup; - } + /* Read file stats */ + r = uv_fs_stat(NULL, &req, filename, NULL); + if (r != 0) { + goto acl_cleanup; + } - uv_fs_req_cleanup(&req); + uv_fs_req_cleanup(&req); - acl_cleanup: - /* Cleanup */ - call_icacls("icacls %s /reset", filename); - uv_fs_unlink(NULL, &unlink_req, filename, NULL); - uv_fs_req_cleanup(&unlink_req); - unlink(filename); - uv_os_free_passwd(&pwd); - ASSERT_OK(r); - MAKE_VALGRIND_HAPPY(loop); - return 0; +acl_cleanup: + /* Cleanup */ + call_icacls("icacls %s /reset", filename); + uv_fs_unlink(NULL, &unlink_req, filename, NULL); + uv_fs_req_cleanup(&unlink_req); + unlink(filename); + uv_os_free_passwd(&pwd); + ASSERT_OK(r); + MAKE_VALGRIND_HAPPY(loop); + return 0; } #endif #ifdef _WIN32 TEST_IMPL(fs_fchmod_archive_readonly) { - uv_fs_t req; - uv_file file; - int r; - /* Test clearing read-only flag from files with Archive flag cleared */ + uv_fs_t req; + uv_file file; + int r; + /* Test clearing read-only flag from files with Archive flag cleared */ - /* Setup*/ - unlink("test_file"); - r = uv_fs_open(NULL, - &req, "test_file", UV_FS_O_WRONLY | UV_FS_O_CREAT, - S_IWUSR | S_IRUSR, - NULL); - ASSERT_GE(r, 0); - ASSERT_GE(req.result, 0); - file = req.result; - uv_fs_req_cleanup(&req); - r = uv_fs_close(NULL, &req, file, NULL); - ASSERT_OK(r); - uv_fs_req_cleanup(&req); - /* Make the file read-only and clear archive flag */ - r = SetFileAttributes("test_file", FILE_ATTRIBUTE_READONLY); - ASSERT(r); - check_permission("test_file", 0400); - /* Try fchmod */ - r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDONLY, 0, NULL); - ASSERT_GE(r, 0); - ASSERT_GE(req.result, 0); - file = req.result; - uv_fs_req_cleanup(&req); - r = uv_fs_fchmod(NULL, &req, file, S_IWUSR, NULL); - ASSERT_OK(r); - ASSERT_OK(req.result); - uv_fs_req_cleanup(&req); - r = uv_fs_close(NULL, &req, file, NULL); - ASSERT_OK(r); - uv_fs_req_cleanup(&req); - check_permission("test_file", S_IWUSR); + /* Setup*/ + unlink("test_file"); + r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_WRONLY | UV_FS_O_CREAT, + S_IWUSR | S_IRUSR, NULL); + ASSERT_GE(r, 0); + ASSERT_GE(req.result, 0); + file = req.result; + uv_fs_req_cleanup(&req); + r = uv_fs_close(NULL, &req, file, NULL); + ASSERT_OK(r); + uv_fs_req_cleanup(&req); + /* Make the file read-only and clear archive flag */ + r = SetFileAttributes("test_file", FILE_ATTRIBUTE_READONLY); + ASSERT(r); + check_permission("test_file", 0400); + /* Try fchmod */ + r = uv_fs_open(NULL, &req, "test_file", UV_FS_O_RDONLY, 0, NULL); + ASSERT_GE(r, 0); + ASSERT_GE(req.result, 0); + file = req.result; + uv_fs_req_cleanup(&req); + r = uv_fs_fchmod(NULL, &req, file, S_IWUSR, NULL); + ASSERT_OK(r); + ASSERT_OK(req.result); + uv_fs_req_cleanup(&req); + r = uv_fs_close(NULL, &req, file, NULL); + ASSERT_OK(r); + uv_fs_req_cleanup(&req); + check_permission("test_file", S_IWUSR); - /* Restore Archive flag for rest of the tests */ - r = SetFileAttributes("test_file", FILE_ATTRIBUTE_ARCHIVE); - ASSERT(r); + /* Restore Archive flag for rest of the tests */ + r = SetFileAttributes("test_file", FILE_ATTRIBUTE_ARCHIVE); + ASSERT(r); - return 0; + return 0; } TEST_IMPL(fs_invalid_mkdir_name) { - uv_loop_t* loop; + uv_loop_t *loop; uv_fs_t req; int r; @@ -4852,7 +4614,6 @@ TEST_IMPL(fs_get_system_error) { return 0; } - TEST_IMPL(fs_stat_batch_multiple) { uv_fs_t req[300]; int r; @@ -4865,7 +4626,7 @@ TEST_IMPL(fs_stat_batch_multiple) { loop = uv_default_loop(); - for (i = 0; i < (int) ARRAY_SIZE(req); ++i) { + for (i = 0; i < (int)ARRAY_SIZE(req); ++i) { r = uv_fs_stat(loop, &req[i], "test_dir", stat_batch_cb); ASSERT_OK(r); } @@ -4877,7 +4638,6 @@ TEST_IMPL(fs_stat_batch_multiple) { return 0; } - #ifdef _WIN32 TEST_IMPL(fs_wtf) { int r; @@ -4895,14 +4655,10 @@ TEST_IMPL(fs_wtf) { ASSERT_OK(r); uv_fs_req_cleanup(&mkdir_req); - file_handle = CreateFileW(L"test_dir/hi\xD801\x0037", - GENERIC_WRITE | FILE_WRITE_ATTRIBUTES, - 0, - NULL, - CREATE_ALWAYS, - FILE_FLAG_OPEN_REPARSE_POINT | - FILE_FLAG_BACKUP_SEMANTICS, - NULL); + file_handle = CreateFileW( + L"test_dir/hi\xD801\x0037", GENERIC_WRITE | FILE_WRITE_ATTRIBUTES, 0, + NULL, CREATE_ALWAYS, + FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL); ASSERT_PTR_NE(file_handle, INVALID_HANDLE_VALUE); CloseHandle(file_handle);