diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2015-08-17 00:44:58 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-08-17 01:07:48 -0400 |
commit | 86c38ef1264f0896510abe7b6eb1f1915986b594 (patch) | |
tree | 391f6090eecd62f9543ed4772d27c8b0b5e8fb00 | |
parent | b1e18dc39325ef50121a28750463a068048d63cb (diff) | |
download | rneovim-86c38ef1264f0896510abe7b6eb1f1915986b594.tar.gz rneovim-86c38ef1264f0896510abe7b6eb1f1915986b594.tar.bz2 rneovim-86c38ef1264f0896510abe7b6eb1f1915986b594.zip |
os_file_is_*: libuv impl
- uv_fs_access() is far more robust than access(). In particular, it
handles utf16 paths (Windows).
- Still need R_OK, W_OK in win_defs.h
-rw-r--r-- | src/nvim/os/fs.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4cb1beb22f..e4776999e5 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -285,7 +285,10 @@ bool os_file_is_readonly(const char *name) bool os_file_is_readable(const char *name) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - return (access(name, R_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. @@ -296,11 +299,11 @@ bool os_file_is_readable(const char *name) int os_file_is_writable(const char *name) 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; } |