diff options
Diffstat (limited to 'src/nvim/os/fs.c')
-rw-r--r-- | src/nvim/os/fs.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 5eeb275701..785c79127f 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -270,13 +270,16 @@ bool os_file_exists(const char_u *name) return os_stat((char *)name, &statbuf); } -/// Check if a file is readonly. +/// Check if a file is readable. /// -/// @return `true` if `name` is readonly. -bool os_file_is_readonly(const char *name) - FUNC_ATTR_NONNULL_ALL +/// @return true if `name` is readable, otherwise false. +bool os_file_is_readable(const char *name) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - return access(name, W_OK) != 0; + uv_fs_t req; + int r = uv_fs_access(&fs_loop, &req, name, R_OK, NULL); + uv_fs_req_cleanup(&req); + return (r == 0); } /// Check if a file is writable. @@ -285,13 +288,13 @@ bool os_file_is_readonly(const char *name) /// @return `1` if `name` is writable, /// @return `2` for a directory which we have rights to write into. int os_file_is_writable(const char *name) - FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - if (access(name, W_OK) == 0) { - if (os_isdir((char_u *)name)) { - return 2; - } - return 1; + uv_fs_t req; + int r = uv_fs_access(&fs_loop, &req, name, W_OK, NULL); + uv_fs_req_cleanup(&req); + if (r == 0) { + return os_isdir((char_u *)name) ? 2 : 1; } return 0; } |