aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/fs.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-08-17 01:10:16 -0400
committerJustin M. Keyes <justinkz@gmail.com>2015-08-17 01:10:16 -0400
commit14d2a90db984c1a0360727c4d9b8337a689fccec (patch)
tree391f6090eecd62f9543ed4772d27c8b0b5e8fb00 /src/nvim/os/fs.c
parent616b787d129b3550dc4b103868cf09e267195210 (diff)
parent86c38ef1264f0896510abe7b6eb1f1915986b594 (diff)
downloadrneovim-14d2a90db984c1a0360727c4d9b8337a689fccec.tar.gz
rneovim-14d2a90db984c1a0360727c4d9b8337a689fccec.tar.bz2
rneovim-14d2a90db984c1a0360727c4d9b8337a689fccec.zip
Merge pull request #3166 from justinmk/file_is_readable
os_file_is_readable()
Diffstat (limited to 'src/nvim/os/fs.c')
-rw-r--r--src/nvim/os/fs.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 5eeb275701..e4776999e5 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -279,19 +279,31 @@ bool os_file_is_readonly(const char *name)
return access(name, W_OK) != 0;
}
+/// Check if a file is readable.
+///
+/// @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
+{
+ 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.
///
/// @return `0` if `name` is not writable,
/// @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;
}